Run code in a sandbox
run_codeRun a code snippet inside a sandbox and return {exit_code, stdout, stderr, timed_out, truncated, duration_ms}. language: python (Python 3.12), node (Node.js 22) or bash. Install packages first with exec_command (pip install … / npm i …). The code is passed to the interpreter on stdin, so it cannot read stdin itself. timeout seconds (default 30, max 55 per call). LONGER JOBS: set background: true — returns a task_id immediately (timeout then defaults to the sandbox's remaining lifetime); poll get_task with the returned offsets to read new output and the exit code, kill_task to stop it. The sandbox keeps billing while a task runs and is not idle-deleted. Output is capped at 1 MiB per stream for synchronous calls. Files and installed state persist between calls in the same sandbox. Requires: token + live sandbox_id. Typical: timed_out after 55 s → repeat with background: true.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| env | No | Optional. Environment variables for this run only (override the ones set at create_sandbox). Example: {"DEBUG": "1"}. | |
| code | Yes | Required. Source code to run, passed to the interpreter on stdin, e.g. "print(2+2)". | |
| timeout | No | Optional. Seconds. Synchronous: max 55. With background: true: up to the sandbox's remaining lifetime (default). | |
| language | Yes | Required. Interpreter: "python" (Python 3.12), "node" (Node.js 22) or "bash". | |
| background | No | Optional. True = run as a background task and return `task_id` at once (poll get_task). Default false (wait up to `timeout`, max 55 s). | |
| sandbox_id | Yes | Required. Sandbox id as returned by create_sandbox / list_sandboxes, e.g. "sb_3f2a…". |