import GboxSDK from "gbox-sdk";
const gboxSDK = new GboxSDK({
apiKey: process.env["GBOX_API_KEY"] // This is the default and can be omitted
});
async function main() {
const box = await gboxSDK.create({ type: "linux" });
// Execute a simple command
const result = await box.command({
commands: ["ls", "-l"]
});
console.log(`Command output: ${result.stdout}`);
console.log(`Command error: ${result.stderr}`);
console.log(`Exit code: ${result.exitCode}`);
// Execute command with timeout
const resultWithTimeout = await box.command({
commands: ["sleep", "10"],
timeout: "5s"
});
console.log(`Timeout result: ${JSON.stringify(resultWithTimeout, null, 2)}`);
}
main();
{
"exitCode": 0,
"stdout": "total 16\ndrwxr-xr-x 4 user user 4096 Jan 15 10:30 .\ndrwxr-xr-x 3 user user 4096 Jan 15 10:25 ..",
"stderr": ""
}
Execute a command on a running box. This endpoint allows you to send commands to the box and receive the output
import GboxSDK from "gbox-sdk";
const gboxSDK = new GboxSDK({
apiKey: process.env["GBOX_API_KEY"] // This is the default and can be omitted
});
async function main() {
const box = await gboxSDK.create({ type: "linux" });
// Execute a simple command
const result = await box.command({
commands: ["ls", "-l"]
});
console.log(`Command output: ${result.stdout}`);
console.log(`Command error: ${result.stderr}`);
console.log(`Exit code: ${result.exitCode}`);
// Execute command with timeout
const resultWithTimeout = await box.command({
commands: ["sleep", "10"],
timeout: "5s"
});
console.log(`Timeout result: ${JSON.stringify(resultWithTimeout, null, 2)}`);
}
main();
{
"exitCode": 0,
"stdout": "total 16\ndrwxr-xr-x 4 user user 4096 Jan 15 10:30 .\ndrwxr-xr-x 3 user user 4096 Jan 15 10:25 ..",
"stderr": ""
}
Enter your API Key in the format: Bearer <token>. Get it from https://gbox.ai
Box ID
"c9bdc193-b54b-4ddb-a035-5ac0c598d32d"
Command execution request parameters
Result of command execution
Was this page helpful?