Skip to main content
Send code to a running sandbox and receive output as a stream of NDJSON events. Each event is flushed as the sandbox produces it — you don’t need to wait for the process to finish before reading output. Python execution uses a persistent REPL, so variables and imports survive across calls. Bash runs in a fresh subprocess each time.

Request

POST /v1/sandboxes/:id/exec
id
string
required
Sandbox id returned by POST /v1/sandboxes.
code
string
required
Source code to execute inside the sandbox.
language
string
default:"python"
Runtime to use. python runs code in the sandbox’s persistent REPL — state carries across calls. bash runs code in a fresh subprocess that exits after each call.

Response

The response is application/x-ndjson. Each line is a JSON event object:
type
string
stdout, stderr, or exit.
data
string | int
For stdout / stderr: one line of text. For exit: the integer exit code.
seq
int
Monotonic counter per exec call. Use this to reorder events that arrive out of sequence.
ts
int
Host wall-clock time in milliseconds since the Unix epoch.

Examples

# Pass -N to disable curl's output buffering so you see events as they arrive.
curl -N -X POST https://api.podflare.dev/v1/sandboxes/$SID/exec \
  -H "Authorization: Bearer $PODFLARE_API_KEY" \
  -H "content-type: application/json" \
  -d '{"code": "print(6*7)"}'
Streaming response (200)
{"type":"stdout","data":"42","seq":0,"ts":1776510028036}
{"type":"exit","data":0,"seq":1,"ts":1776510028037}

Execution semantics

Timing reference

OperationApproximate wall clock
run_code("print(6*7)") in a warm pool-hit sandbox~3–5 ms
First import pandas (cold file cache)~500 ms
Subsequent import pandas (warm page cache)~150 ms

Error responses

StatusBodyCause
401{"error": "invalid api key"}Missing or invalid bearer token
404{"error": "sandbox not found"}Sandbox id does not exist
500{"error": "..."}Agent did not respond or executor error