Skip to main content
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({
    command: "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({
    command: "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

command
string
required

The command to run

Example:

"ls -la"

envs
object

The environment variables to run the command

Example:
{
"PATH": "/usr/bin:/bin",
"NODE_ENV": "production"
}
workingDir
string

The working directory of the command. It not provided, the command will be run in the box.config.workingDir directory.

Example:

"/home/user/projects"

timeout
string
default:30s

The timeout of the command. If the command times out, the exit code will be 124. For example: 'timeout 5s sleep 10s' will result in exit code 124.

Supported time units: ms (milliseconds), s (seconds), m (minutes), h (hours) Example formats: "500ms", "30s", "5m", "1h" Default: 30s

Example:

"30s"

Response

200 - application/json

Result of command execution

exitCode
number
required

The exit code of the command

Example:

0

stdout
string
required

The standard output of the command

Example:

"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
string
required

The standard error output of the command

Example:

""

I