Run a command and stream output over SSE
Runs a command and streams its output as Server-Sent Events while it
runs. Each data: line is a JSON object: an output chunk
({"stdout":"..."} or {"stderr":"..."}), the terminal event
({"exit_code":N,"finished":true}), or an error
({"error":"...","finished":true}). The stream closes when the command
exits. The sandbox must be running; a paused sandbox returns 503.
Activate it first with POST /sandboxes/{sandbox_id}/activate (the SDKs
do this automatically).
timeout_s is a hard runtime limit: the command is killed after that
many seconds regardless of output, exiting with code 124.
Authorizations
Per-sandbox token returned by create, resume, and activate. Grants access to a single sandbox's files and commands. Distinct from the team X-API-Key.
Body
Command to execute. Wrapped in /bin/sh -c unless args is provided.
1If provided, command is used as the binary and args as arguments (no shell wrapping).
Environment variables for the command.
Working directory (default /home/user).
Timeout in seconds.
Response
A Server-Sent Events stream of output and lifecycle events.
One Server-Sent Event from POST /exec/stream, delivered as a data: line carrying this JSON object. Output events carry stdout or stderr (each with a timestamp); the terminal event carries finished: true with exit_code, or error and code if the command could not be run. The stream may also include SSE comment keepalive lines (: keepalive), which carry no data.
RFC 3339 time the event was emitted (output and terminal events).
A chunk of standard output.
A chunk of standard error.
Present and true on the terminal event.
Process exit code, on the terminal event.
Error message if the command could not be run.
Error code accompanying error (e.g. bad_request, exec_failed).