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 | Environment variables for this run only (override the ones set at create_sandbox). | |
| code | Yes | ||
| timeout | No | Seconds. Synchronous: max 55. With background: true: up to the sandbox's remaining lifetime (default). | |
| language | Yes | ||
| background | No | ||
| sandbox_id | Yes | Sandbox id as returned by create_sandbox / list_sandboxes, e.g. "sb_3f2a…". |