Skip to content

Running code (exec)

exec runs work inside a sandbox on the managed API:

  • POST /v1/sandboxes/{id}/exec — run in an existing running sandbox. Files and processes persist between execs; execs are serialized (one at a time, FIFO).

The body is a superset that supports several ways to express a step. Provide whichever fields you need; files are materialized first, then the command runs.

FieldTypeDescription
commandstringA single shell command string. The simplest path.
codestringSource code, run via the template's interpreter (e.g. python3).
commandsstring[][]A list of argv arrays, run sequentially.
filesFileSpec[]Files written into the guest before the command runs.
timeout_secondsintegerMax wall-clock for the exec (guest-side). The sandbox accepts up to 3600.
seedstringPin the guest CRNG for this exec — 64 hex chars. Omitted ⇒ fresh entropy. See replay.
egressobjectPer-exec egress policy override (net templates). See per-fork egress.
FieldTypeDescription
pathstringPath inside the guest (relative to the working dir, or absolute).
contentstringFile contents (UTF-8).

Stage a file and run it:

Terminal window
curl https://api.collimate.ai/v1/sandboxes/sbx_9f2a1c7b3e40/exec \
-H "Authorization: Bearer $COLLIMATE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"files": [{ "path": "solve.py", "content": "print(6 * 7)" }],
"command": "python3 solve.py",
"timeout_seconds": 30
}'

Run a batch of argv steps in order:

{
"commands": [
["git", "clone", "https://github.com/acme/repo", "/w"],
["make", "-C", "/w", "test"]
],
"timeout_seconds": 300
}
{
"id": "sbx_9f2a1c7b3e40",
"stdout": "42\n",
"stderr": "",
"exit_code": 0,
"fork_time_ms": 0.0,
"exec_time_ms": 9.7,
"total_time_ms": 10.2,
"seed": "3a7f0b…",
"seed_ack": "verified"
}
FieldTypeDescription
idstringThe sandbox this exec ran in.
stdoutstringCaptured standard output.
stderrstringCaptured standard error.
exit_codeintegerProcess exit code.
fork_time_msnumberFork time (0 for a warm session exec).
exec_time_msnumberTime the command spent running in the guest.
total_time_msnumberEnd-to-end server-side time.
seedstringThe 32-byte guest CRNG seed this exec ran with (hex).
seed_ackstringSeed-ack verdict: verified, no-ack, off, or a mismatch. See replay.

The API holds the connection open while your command runs, up to timeout_seconds (max 3600). One exec's merged output is capped in the guest (16 MiB) — beyond that the frame is truncated, so stream large artifacts to a file and download them instead of printing them.