Run a command
Runs a shell command inside the sandbox as an unprivileged user and waits for it to finish. Output is capped at 1 MiB per stream; anything beyond that sets truncated.
With stream: true the response is a Server-Sent Events stream instead of a single JSON body: output arrives as it is produced, and disconnecting before the terminal event kills the command (recorded with status: "cancelled"). The terminal exit event carries the same object the non-streaming call returns.
The call returns when nothing it started still holds the output stream open — not when the foreground command exits, so a trailing & alone does not end it. In particular cd /workspace && nohup server & backgrounds a subshell, which keeps the call open for the full timeout_ms and then returns exit_code: 124; when the timeout fires, that command and every process it started are killed, including the detached one. Pass cwd instead of prefixing cd.
Request
- Base URL: https://sandbox-as-a-service.com/v1
- URL: https://sandbox-as-a-service.com/v1/sandboxes/{id}/exec
- Auth: HTTP bearer
Request body
Example request
{
"command": "python3 -c \"print(6*7)\""
}Response
The command finished. A non-zero exit_code is still a 200 response. With stream: true the body is a text/event-stream (headers Cache-Control: no-cache, no-transform and X-Accel-Buffering: no) instead of a single JSON document. Its events: start once, first, as {"id":"exec_…","sandbox_id":"…"}; stdout/stderr as {"data":"<chunk>"} as output arrives (a multi-byte UTF-8 character split across transport chunks is delivered whole); the comment line : ping at least every 15 s as a heartbeat; and exactly one terminal exit whose data is the same Execution object the non-streaming call returns (a failure after the stream started is instead one error event carrying the standard error object). Disconnecting before exit kills the command and records it with status: "cancelled". Output past the 1 MiB per-stream storage cap keeps streaming live but is not stored; the stored record and the exit event then carry truncated: true.
Example response
{
"id": "exec_4b1d2e3f4a5b6c7d",
"sandbox_id": "sbx_9f2c4a1b8d3e6f0a12",
"stdout": "hello from the sandbox\n",
"duration_ms": 412
}Changes
No recorded changes to this operation across all 1 revision of this API.