POST
/
boxes
/
{boxId}
/
commands
JavaScript
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": ""
}

Authorizations

Authorization
string
header
required

Enter your API Key in the format: Bearer <token>. Get it from https://gbox.ai

Path Parameters

boxId
string
required

Box ID

Example:

"c9bdc193-b54b-4ddb-a035-5ac0c598d32d"

Body

application/json

Command execution request parameters

Response

200 - application/json

Result of command execution