---
title: SDK and CLI · Sandboxes docs
description: Build, check and run Agent Playground flows from TypeScript, Python or the qr command line, and keep flows as JSON in your repository.
url: https://www.quietrobot.ai/docs/sandboxes/playground/sdk
---

# SDK and CLI

Build, check and run Agent Playground flows from TypeScript, Python or the qr command line, and keep flows as JSON in your repository.

> [!NOTE]
> Sandboxes is in early access. It is free to try, some parts are still in testing, and details may change.

The TypeScript and Python SDKs and the `qr` command line wrap the [Flows API](https://www.quietrobot.ai/docs/sandboxes/playground/api). Install them as on the [SDK](https://www.quietrobot.ai/docs/sandboxes/sdk), [Python](https://www.quietrobot.ai/docs/sandboxes/python) and [CLI](https://www.quietrobot.ai/docs/sandboxes/cli) pages, and set `QR_API_KEY`.

> [!NOTE]
> Flows and runs arrive in the next release of the SDKs and the `qr` command line. Until then, use the [HTTP calls](https://www.quietrobot.ai/docs/sandboxes/playground/api).

## Run a recipe, watch it, read the result

```ts
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, { guards: { maxLoops: 3 } });
const done = await qr.runs.wait(run.id, { onStep: (s) => console.log(s.label, s.status) });
console.log(done.status, done.loops, done.costUsd);
```

```python
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"], guards={"maxLoops": 3})
run = qr.runs.wait(run["id"], on_step=lambda s, r: print(s["label"], s["status"]))
print(run["status"], run["loops"], run["costUsd"])
```

A step that your [Policies](https://www.quietrobot.ai/docs/sandboxes/approvals) hold shows as `waiting` until a person decides in the dashboard. A run that needs more sandboxes at once than your plan allows throws a `plan_limit` error before anything starts.

## Build a flow in code

```ts
const flow = await qr.flows.create({
  name: "Fix my tests",
  graph: {
    start: "test",
    secrets: ["ANTHROPIC_API_KEY"],
    nodes: [
      { id: "test", kind: "run", label: "Run tests", cmd: "python3 -m pytest -q" },
      { id: "fix", kind: "agent", label: "Fix it", goal: "Make the tests pass. They said:\n{{steps.test.output}}", done: "python3 -m pytest -q" },
      { id: "done", kind: "end", label: "Fixed" },
    ],
    edges: [
      { from: "test", to: "fix", when: "fail" },
      { from: "fix", to: "test" },
      { from: "test", to: "done", when: "pass" },
    ],
  },
  guards: { maxLoops: 4, timeSec: 600, budgetUsd: 1 },
});
```

It opens in the builder like a flow you drew. The fields of each step are in [Write a flow as JSON](https://www.quietrobot.ai/docs/sandboxes/playground/api#write-a-flow-as-json).

## Check a flow first

`validate` runs the same checks as **Run**, without saving or starting anything: the flow itself, your plan's sandboxes at once, your keys, and the steps your Policies will likely hold. A flow that wouldn't run comes back with `valid: false` and its problems; it doesn't throw.

```ts
const check = await qr.flows.validate({ graph, guards }); // or { flow: "flw_123" } or { recipe: "pr-reviewer" }
if (!check.valid) {
  for (const p of check.problems) console.log(`${p.code} at ${p.path ?? p.step ?? "the flow"}: ${p.message}`);
  process.exit(1);
}
console.log(`${check.sandboxes.atOnce} of ${check.sandboxes.limit} sandboxes at once`, check.policy);
```

```python
check = qr.flows.validate({"graph": graph, "guards": guards})  # or flow="flw_123" or recipe="pr-reviewer"
for p in check["problems"]:
    print(p["code"], p.get("path"), p["message"])
```

The codes are listed on the [Flows API](https://www.quietrobot.ai/docs/sandboxes/playground/api#check-a-flow-before-you-save-or-run-it) page.

## Keep flows in your repository

Export a flow as JSON, change it in your editor or in a pull request, check it, and save it back. The JSON is the same document the builder's JSON view shows.

```ts
import { readFileSync, writeFileSync } from "node:fs";

writeFileSync("flows/fix.json", JSON.stringify(await qr.flows.export("flw_123"), null, 2));

// later, in CI
const doc = JSON.parse(readFileSync("flows/fix.json", "utf8"));
const check = await qr.flows.validate(doc);
if (check.valid) await qr.flows.update("flw_123", doc);
```

```python
import json

with open("flows/fix.json", "w") as f:
    json.dump(qr.flows.export("flw_123"), f, indent=2)

doc = json.load(open("flows/fix.json"))
if qr.flows.validate(doc)["valid"]:
    qr.flows.update("flw_123", name=doc["name"], graph=doc["graph"], guards=doc["guards"])

copy = qr.flows.import_flow(doc, name="Fix my tests (copy)")  # a new flow, here or in another organization
```

`qr.flows.schema()` returns the flow's JSON Schema, for tools that check or complete flow JSON.

## The qr command line

```bash
qr recipes list
qr flows create --recipe fix-until-pass      # prints the new flow's id
qr flows list
qr flows export flw_123 -o flows/fix.json    # the flow as JSON
qr flows validate flows/fix.json             # exits 1 and lists the problems when it wouldn't run
qr flows update flw_123 flows/fix.json       # save your edits back
qr flows create flows/fix.json               # or save them as a new flow
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_123
```

`qr flows validate` exits `1` when the flow wouldn't run, so it fits in a CI step:

```yaml
- run: pip install quietrobot-sandboxes && qr flows validate flows/fix.json
  env:
    QR_API_KEY: ${{ secrets.QR_API_KEY }}
```

## Everything else

Both SDKs also have `qr.recipes.list()` and `get`, `qr.flows.list()`, `get`, `delete`, `runs`, `versions`, `saveVersion` (`save_version` in Python) and `restore`, `qr.runs.create`, `list`, `get` and `cancel`, and `qr.graphs.simulate` for a flow you haven't saved.
