Skip to main content
POST
/
boxes
/
{boxId}
/
run-code
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" });

  // Run Python code
  const pythonResult = await box.runCode({
    code: `print("Hello from Python!")`,
    language: "python"
  });

  console.log("Python execution result:");
  console.log(`Exit code: ${pythonResult.exitCode}`);
  console.log(`Output:\n${pythonResult.stdout}`);
  if (pythonResult.stderr) {
    console.log(`Errors:\n${pythonResult.stderr}`);
  }
}

main();
{
  "exitCode": 0,
  "stdout": "Hello, World!\n5",
  "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

Request parameters for running code in various languages

code
string
required

The code to run

Example:

"print('Hello, World!')\nprint(2 + 3)"

language
enum<string>
default:python

The language of the code.

Available options:
bash,
python,
typescript
Example:

"python"

envs
object

The environment variables to run the code

Example:
{
"PYTHONPATH": "/usr/lib/python",
"DEBUG": "true"
}
argv
string[]

The arguments to run the code. For example, if you want to run "python index.py --help", you should pass ["--help"] as arguments.

Example:
["--help"]
workingDir
string

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

Example:

"/home/user/scripts"

timeout
string
default:30s

The timeout of the code execution. If the code execution times out, the exit code will be 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 code execution

exitCode
number
required

The exit code of the code

Example:

0

stdout
string
required

The stdout of the code

Example:

"Hello, World!\n5"

stderr
string
required

The stderr of the code

Example:

""

I