sandbox.commands. Running a command on a paused sandbox transparently resumes it and executes.
run (synchronous)
Execute a command and wait for it to finish. Returns a CommandResult.
run (streaming)
Pass onStdout / on_stdout and/or onStderr / on_stderr callbacks. Output is delivered over Server-Sent Events and flushed to your callback as it arrives. The final result still contains the full concatenated output.
The timeout is a wall-clock limit, also for streamed commands. Output does not reset it. At the limit, the command stops and
run() returns exit code 124. See Timeouts for the defaults.spawn (interactive session)
spawn() hands back a CommandSession while the process is still running. Stream its output with callbacks, write to stdin, signal it, and call wait() for the result. Output comes over a WebSocket. The sessions guide walks through it.
In Python,
spawn() is on AsyncSandbox only; the synchronous version raises. It takes the same cwd, user, env, timeoutMs / timeout_seconds, onStdout / on_stdout, and onStderr / on_stderr options as run. Unlike run, it has no default timeout, so leave the timeout off for a long-lived process.CommandSession
In Python the methods are awaitable (
await session.stdin.write(...), await session.kill(), await session.wait()) and the session is an async with context manager. In TypeScript the session supports await using for automatic cleanup.
Options
CommandResult
exitCode / exit_code is 124 when the command reached its timeout.
truncated is true when the output of a run() without callbacks reached the 8 MiB cap on JSON-encoded stdout and stderr combined. Escaped characters count for more than one byte, so the cap can be reached below 8 MiB of raw output. The sandbox drops the rest of the output and appends a notice to stderr. Streamed runs return the full output, and truncated is always false for them.
Non-zero exit codes
run() does not raise for non-zero exits. Inspect the exit code yourself.
Errors
Commonly raised:TimeoutError/SandboxTimeoutError: the SDK stopped waiting for a response. A syncrun()without a timeout throws this after 30 seconds. A command that reaches its own timeout doesn’t throw: it returns exit code124.ValidationError: an invalidtimeoutMs, or a response larger thanmaxOutputBytes(TypeScript)NotFoundError: the sandbox was deletedConflictError: the sandbox is in an invalid stateSandboxError: the connection dropped before the command finished (streaming andspawn), or a TypeScriptsignalaborted arun(). The sandbox stops a streamedrun()command or aspawn()process. Arun()without callbacks keeps running until it exits or reaches its timeout. None can be reattached.