Sandboxes
SDK, CLI and API
Save, simulate and run Agent Playground flows from code, the command line or plain HTTP, and write flows as JSON.
Everything the builder does, you can do from code. A flow you draw in the builder and a flow you send as JSON are the same thing: you can draw a flow and run it from your CI, or generate one in code and open it in the builder.
All calls use an API key. A read-only key can list and read flows and runs, and simulate. Saving, starting and stopping runs need a full key.
Run a recipe or a saved flow
The quickest way to start: run a recipe by its id, or a flow you saved in the builder (its id starts with flw_ and is in the builder's address bar).
export QR_API_KEY=qr_live_...
# Run a recipe
curl -s -X POST https://api.quietrobot.ai/api/v1/runs -H "Authorization: Bearer $QR_API_KEY" \
-d '{"recipe":"fix-until-pass"}'
# Run your saved flow, with tighter limits for this run
curl -s -X POST https://api.quietrobot.ai/api/v1/flows/flw_123/runs -H "Authorization: Bearer $QR_API_KEY" \
-d '{"guards":{"maxLoops":3,"timeSec":600,"budgetUsd":0.50}}'Both answer 201 with the run. Then check on it:
curl -s https://api.quietrobot.ai/api/v1/runs/run_123 -H "Authorization: Bearer $QR_API_KEY"Poll every few seconds until status is done, failed, stopped (it reached a limit) or cancelled. Stop it early with POST /runs/run_123/cancel.
Simulate first
Get the same forecast the builder shows, before you spend anything:
curl -s -X POST https://api.quietrobot.ai/api/v1/graphs/simulate -H "Authorization: Bearer $QR_API_KEY" \
-d '{"flow":"flw_123","guards":{"maxLoops":5,"timeSec":300,"budgetUsd":0.25}}'{
"forecast": {
"costUsd": { "p50": 0.0009, "p90": 0.0014 },
"seconds": { "p50": 38, "p90": 55 },
"loops": { "mean": 2.8, "p90": 4 },
"outcomes": { "done": 1800, "failed": 0, "guard": 200 },
"guardHits": { "loops": 0.1, "time": 0, "budget": 0 },
"worstCaseUsd": 0.0031,
"worstCaseWhy": "the time cap (180s) on up to 1 sandbox",
"modelCostUsd": { "p50": 0, "p90": 0 },
"notes": []
}
}p50 is the typical run and p90 one run in ten. A CI job can refuse to start a run whose worstCaseUsd is over budget.
Write a flow as JSON
A flow is a list of steps (nodes) and arrows (edges):
{
"name": "Fix until tests pass",
"template": "base",
"start": "get",
"secrets": ["ANTHROPIC_API_KEY"],
"nodes": [
{ "id": "get", "kind": "run", "label": "Get the code", "cmd": "git clone https://github.com/you/app proj" },
{ "id": "test", "kind": "run", "label": "Run tests", "cwd": "proj", "cmd": "python3 -m pytest -q" },
{ "id": "fix", "kind": "agent", "label": "Fix it",
"goal": "Make the tests in proj pass without changing them. They said:\n{{steps.test.output}}",
"maxTurns": 12, "maxUsd": 0.5, "done": "cd proj && python3 -m pytest -q" },
{ "id": "done", "kind": "end", "label": "Fixed" }
],
"edges": [
{ "from": "get", "to": "test" },
{ "from": "test", "to": "fix", "when": "fail" },
{ "from": "fix", "to": "test" },
{ "from": "test", "to": "done", "when": "pass" }
],
"rewindTo": "get"
}templateis the sandbox template the run starts from.startis the first step. It must run something in the main sandbox.secretslists the saved secrets the run may use. AI steps needANTHROPIC_API_KEYhere.rewindTois the step whose checkpoint the sandbox goes back to if a limit stops the run.- An edge's
whenispass(the default),fail,always(either way), orchoice:<label>after an AI choice.
Step kinds
kind | Block | Main fields |
|---|---|---|
run | Run command | cmd, cwd, files (a map of path to text, written before it runs) |
code | Run code | code, lang (python, node or bash) |
model | Ask AI | prompt, model, key, output (text, json or decision), choices, schema, expect, out |
agent | Agent | goal, model, key, tools (shell, files), maxTurns, maxUsd, done |
team | Agents together | members (2 to 6 step ids), need (all or any) |
branch | Decide | cmd: exit 0 follows pass, anything else fail |
approval | Approval | ask, the question for the person |
wait | Wait | seconds, 1 to 600 |
fork | Try in parallel | lanes, 2 to 10 names |
judge | Keep the best | metric, best (min or max) |
end | Output |
Every step has an id and a label. Steps that run something also take sandbox (a lane name, or the main sandbox when left out), timeoutMs, checkpoint, network: "none", approve: true (ask a person first), and the forecast hints estSec and passRate. Models are claude-sonnet-5-5 (the default), claude-opus-5-5 and claude-haiku-5-5.
A flow's own rules go in policy:
"policy": {
"network": { "mode": "allowlist", "allow": ["pypi.org", "*.github.com"], "lock": true },
"hold": [{ "pattern": "git push|npm publish", "description": "Publishing needs a person" }]
}mode is deny, allowlist or open. A flow that breaks a rule (an unknown step in an edge, a reference to a later step, a lane no fork makes) is refused with a message that names the step.
Save flows
# Save a new flow from a recipe, or from your own JSON
curl -s -X POST https://api.quietrobot.ai/api/v1/flows -H "Authorization: Bearer $QR_API_KEY" -d '{"recipe":"pr-reviewer"}'
curl -s -X POST https://api.quietrobot.ai/api/v1/flows -H "Authorization: Bearer $QR_API_KEY" \
-d @- <<'EOF'
{ "name": "Fix my tests", "graph": { ... }, "guards": { "maxLoops": 3, "timeSec": 600, "budgetUsd": 1 } }
EOFThe flow opens in the builder like any other. A saved flow can be a draft that can't run yet: runnable is false and problem says why.
| Call | What it does |
|---|---|
GET /recipes, GET /recipes/{id} | The recipes, with their category, default limits (guards), flow, and needsKey |
GET /flows, POST /flows | List your flows, save a new one |
GET, PUT, DELETE /flows/{id} | Read, change (fields you leave out keep their value) or delete a flow. Deleting keeps its runs. |
GET /flows/{id}/versions, POST /flows/{id}/versions | List versions, newest first; save one with an optional note |
GET /flows/{id}/versions/{n} | One version, with its flow |
POST /flows/{id}/restore | {"version": n} restores a version |
GET /flows/{id}/runs, POST /flows/{id}/runs | List a flow's runs, start one |
POST /graphs/simulate | Forecast a graph, recipe or flow |
POST /runs | Start a run of a graph, recipe or flow, with optional guards, size and metadata |
GET /runs, GET /runs/{id} | Recent runs; one run with its steps |
POST /runs/{id}/cancel | Stop a run |
size picks the sandbox size for the run, like {"cpuClass": "standard", "cpus": 2, "memoryMb": 4096}. The default is your plan's default size. metadata is up to 16 strings of your own, kept with the run.
The run object
{
"id": "run_...", "name": "Fix until tests pass", "recipe": "fix-until-pass",
"status": "done", "guards": { "maxLoops": 5, "timeSec": 180, "budgetUsd": 0.05 },
"loops": 3, "costUsd": 0.0011, "modelCostUsd": 0, "elapsedSec": 41.2,
"flowId": null, "flowVersion": null, "stopReason": null, "error": null,
"steps": [
{ "seq": 1, "node": "setup", "label": "Set up project", "status": "ok",
"message": "Project ready, 4 attempts prepared", "output": "...",
"costUsd": 0.0001, "durationMs": 1830, "snapshotId": "snp_..." }
]
}A step's status is running, waiting (for a person), ok, fail, stopped or skipped. An agent step also has agent, its turn-by-turn replay: each turn's text, tool calls with exit codes and output, tokens and cost, and the final check.
TypeScript and Python SDKs
Note
Flows and runs arrive in the next release of the SDKs and the
qrcommand line. Until then, use the HTTP calls above.
import { Sandboxes } from "@quietrobot/sandboxes";
const qr = new Sandboxes(); // reads QR_API_KEY
const flow = await qr.flows.create({ recipe: "fix-until-pass" });
const { forecast } = await qr.flows.simulate(flow.id);
console.log("1 in 10 runs cost more than", forecast.costUsd.p90);
const run = await qr.flows.run(flow.id);
const done = await qr.runs.wait(run.id, { onStep: (s) => console.log(s.label, s.status) });
console.log(done.status, done.loops, done.costUsd);from quietrobot_sandboxes import Sandboxes
qr = Sandboxes() # reads QR_API_KEY
flow = qr.flows.create(recipe="fix-until-pass")
forecast = qr.flows.simulate(flow["id"])["forecast"]
print("1 in 10 runs cost more than", forecast["costUsd"]["p90"])
run = qr.flows.run(flow["id"])
run = qr.runs.wait(run["id"], on_step=lambda s, r: print(s["label"], s["status"]))
print(run["status"], run["loops"], run["costUsd"])Both also have qr.recipes.list(), qr.flows.list(), get, update, delete, versions, saveVersion (save_version in Python) and restore, plus qr.runs.create, list, get and cancel, and qr.graphs.simulate for a flow you haven't saved.
The qr command line
qr recipes list
qr flows create --recipe fix-until-pass # prints the new flow's id
qr flows list
qr graph simulate --flow flw_123 --budget 0.10
qr flows run flw_123 --max-loops 3 --wait # prints each step as it happens
qr run list
qr run show run_123
qr run cancel run_123qr graph simulate and qr run start also take a JSON file: qr run start fix.json --wait.
Track your own loops
Already have an agent loop in your own code, or in LangGraph? You can still see it in the Playground's run view and use its limits. Start a run with "mode": "external" and a flow that only names the steps, then report each step as your code runs it:
curl -s -X POST https://api.quietrobot.ai/api/v1/runs/run_123/steps -H "Authorization: Bearer $QR_API_KEY" \
-d '{"node":"test","status":"fail","sandboxId":"sbx_...","message":"2 tests failed"}'The answer says "stop": true once a limit is reached, and your code should stop there. Reported runs show in Recent runs marked "reported".