Skip to main content
Run shell commands inside a sandbox via 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.
Streaming uses an idle timeout: the timer resets on every chunk. A command that keeps producing output never trips it, however long it runs. A command that goes silent still has to finish before the timeout.

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, env, timeoutMs / timeout_seconds, onStdout, and onStderr options as run. 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

Non-zero exit codes

run() does not raise for non-zero exits. Inspect the exit code yourself.

Errors

Commonly raised:
  • TimeoutError / SandboxTimeoutError: the timeout elapsed before the command finished
  • NotFoundError: the sandbox was deleted
  • ConflictError: the sandbox is in an invalid state
  • SandboxError: the connection dropped mid-stream without a terminal finished event (streaming only)
See Errors for the full hierarchy.