---
title: Coding recipes · Sandboxes docs
description: Six worked examples for code: fix until the tests pass, let an agent fix a test, review a pull request, try upgrade plans side by side, reproduce a bug, and keep a README's examples working.
url: https://www.quietrobot.ai/docs/sandboxes/playground/recipes/coding
---

# Coding recipes

Six worked examples for code: fix until the tests pass, let an agent fix a test, review a pull request, try upgrade plans side by side, reproduce a bug, and keep a README's examples working.

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

Each recipe below says what it does, shows its shape, walks through its steps, and ends with how to make it your own. Open **Agent Playground**, choose **Use this recipe**, and follow along. See [Recipes](https://www.quietrobot.ai/docs/sandboxes/playground/recipes) for how recipes work.

## Fix until tests pass

**The pattern:** a loop. Run the tests; if they fail, fix and run them again; stop when they pass or the loop limit is reached.

```flow
{"title": "Fix until tests pass", "nodes": [["setup", "run", "Set up project"], ["write", "run", "Write code"], ["test", "run", "Run tests"], ["fix", "run", "Fix failures"], ["save", "run", "Save result"]], "edges": [["setup", "write"], ["write", "test"], ["test", "fix", "Failed"], ["fix", "test", "Passed"], ["test", "save", "Passed"]]}
```

| Step | Block | What it does |
|---|---|---|
| Set up project | Run command | Writes a small project: a `slugify` function's tests, and four tries at the function. |
| Write code | Run command | Puts the first try in place. |
| Run tests | Run command | Runs the tests. Passed goes to Save result, Failed goes to Fix failures. |
| Fix failures | Run command | Swaps in the next, slightly better try, then goes back to Run tests. |
| Save result | Run command | Packs the working code into `result.tgz`. |

**Limits:** 5 loops, 180 seconds, $0.05. **If stopped, go back to:** Write code.

**What you'll see:** Run tests fails three times, each time with fewer failures ("FAIL slugify('Café au lait')..."), and passes on the fourth. The timeline shows **First pass**, **Loop 1**, **Loop 2** and **Loop 3**.

**Make it yours:** change **Set up project** to clone your repository and install what it needs, and **Run tests** to your test command (`npm test`, `pytest -q`, `go test ./...`). Replace **Fix failures** with an **Agent** whose goal is to fix the failures, as in the next recipe.

## Agent fixes the failing test

**Needs a Claude key.** **The pattern:** an agent with a check. Instead of a loop you draw, the agent loops by itself, turn by turn, until a check passes.

```flow
{"title": "Agent fixes the failing test", "nodes": [["setup", "run", "Set up project"], ["agent", "agent", "Agent fixes it", "12 turns · $0.50 · check: tests"], ["show", "run", "Show the fix"], ["done", "end", "Fixed"]], "edges": [["setup", "agent"], ["agent", "show", "Done"], ["show", "done"]]}
```

| Step | Block | What it does |
|---|---|---|
| Set up project | Run command | Writes `slugify.py` with a bug, and its tests. Runs the tests once so you see them fail. |
| Agent fixes it | Agent | Goal: fix `slugify.py` so the tests pass, using only the standard library, without changing the tests. It gets the setup step's output through a reference. Up to 12 turns and $0.50. **Check that it worked:** the tests. |
| Show the fix | Run command | Runs the tests again and prints the fixed file. |

**Limits:** 2 loops, 600 seconds, $0.75. **If stopped, go back to:** Set up project.

**What you'll see:** open the agent step to replay it. Typically Claude runs the tests, reads `slugify.py`, writes a fix, runs the tests again, and stops once the check passes, in a handful of turns and a few cents.

**Make it yours:** point the setup step at your repository and change the agent's **Goal** and **Check that it worked** to your test command. Turn on **No internet for this step** if the fix shouldn't need the internet. Turn on **Ask a person first** to approve each command while you get to know it.

## PR reviewer

**The pattern:** checks that run whatever happens, a branch on whether there's anything to say, and a person before anything is posted.

```flow
{"title": "PR reviewer", "nodes": [["co", "run", "Check out PR"], ["lint", "run", "Lint"], ["test", "run", "Run tests"], ["notes", "code", "Write review notes"], ["any", "branch", "Anything to say?"], ["ok", "approval", "Post review?"], ["post", "run", "Post review"], ["clean", "end", "Looks good"], ["held", "end", "Not posted"]], "edges": [["co", "lint"], ["lint", "test", "Either way"], ["test", "notes", "Either way"], ["notes", "any"], ["any", "ok", "Yes"], ["any", "clean", "No"], ["ok", "post", "Approved"], ["ok", "held", "Denied"]]}
```

| Step | Block | What it does |
|---|---|---|
| Check out PR | Run command | Writes a small app and a pull request's changes. |
| Lint | Run command | A small linter finds an unused import, a bare `except` and a `TODO`. |
| Run tests | Run command | Runs the tests and saves what they print. |
| Write review notes | Run code | Turns the findings and test result into a review draft. |
| Anything to say? | Decide | `test -s repo/findings.txt`: Yes if there are findings. |
| Post review? | Approval | "Post these review comments on PR #42?" |
| Post review | Run command | Saves the final review. In the recipe, nothing is sent to GitHub. |

**What you'll see:** the run stops at **Post review?** and waits. Open **Approvals**, read the draft in the step's output, and approve or deny. The arrows from Lint and Run tests use **Either way**, so a failing lint still gets reviewed.

**Make it yours:** check out a real pull request (`git clone` then `git fetch origin pull/42/head`), use your own linters, and replace **Write review notes** with an **Ask AI** step that writes the review from the lint and test output. Make **Post review** call your code host's API. Your organization's rules will hold outgoing `curl` calls for a person anyway.

## Dependency upgrade bot

**The pattern:** parallel lanes that each try a different plan, keep the boldest one that still works, then a person.

```flow
{"title": "Dependency upgrade bot", "nodes": [["setup", "run", "Check out the app"], ["out", "run", "List what's out of date", "no network"], ["fork", "fork", "Fork ×3", "Patch, Minor, Latest"], ["patch", "run", "Patches only", "Lane Patch"], ["minor", "run", "Patches and minors", "Lane Minor"], ["latest", "run", "Everything to latest", "Lane Latest"], ["judge", "judge", "Most upgrades, tests pass", "highest upgraded"], ["ok", "approval", "Open the pull request?"], ["pr", "code", "Draft the pull request"], ["held", "end", "Not opened"]], "edges": [["setup", "out"], ["out", "fork"], ["fork", "patch"], ["fork", "minor"], ["fork", "latest"], ["patch", "judge"], ["minor", "judge"], ["latest", "judge"], ["judge", "ok", "Passed"], ["ok", "pr", "Approved"], ["ok", "held", "Denied"]]}
```

| Step | Block | What it does |
|---|---|---|
| Check out the app | Run command | Writes an app with three libraries and passing tests. |
| List what's out of date | Run command | Lists available upgrades, with the network off. |
| Patches only, Patches and minors, Everything to latest | Run command, one per lane | Each lane applies its plan and runs the tests, printing how many libraries it upgraded. |
| Most upgrades, tests pass | Keep the best | Keeps the lane with the highest `upgraded` count whose tests passed. |
| Open the pull request? | Approval | A person decides. |
| Draft the pull request | Run code | Writes the pull request's description. |

**What you'll see:** the **Latest** lane breaks the tests and drops out. **Minor** upgrades more than **Patch**, so it wins and becomes the main sandbox.

**Make it yours:** use your package manager's commands in each lane (`npm update`, `npm install pkg@latest`, `pip install -U`), keep your test command at the end of each lane, and print `{"upgraded": N}`. The lanes run at the same time, so three plans take as long as one.

## Reproduce a bug from an issue

**The pattern:** a loop with two ways out. It keeps writing small tests until one fails the way the bug report says, or until it runs out of ideas.

```flow
{"title": "Reproduce a bug from an issue", "nodes": [["setup", "run", "Check out the code"], ["write", "code", "Write the next test"], ["run", "branch", "Does the test pass?", "no network"], ["match", "branch", "Fails as described?"], ["comment", "run", "Draft the repro comment"], ["ask", "run", "Ask for more detail"]], "edges": [["setup", "write"], ["write", "run", "Passed"], ["write", "ask", "Failed"], ["run", "write", "Yes"], ["run", "match", "No"], ["match", "comment", "Yes"], ["match", "write", "No"]]}
```

| Step | Block | What it does |
|---|---|---|
| Check out the code | Run command | Writes a shopping cart module and a bug report about a coupon. |
| Write the next test | Run code | Writes one more small test. Fails when it has no ideas left. |
| Does the test pass? | Decide | Runs it with the network off. If it passes, the bug didn't show: try another test. |
| Fails as described? | Decide | Checks the failure matches the report. If not, it's a different problem: try another. |
| Draft the repro comment | Run command | Writes a comment with the test that shows the bug. |
| Ask for more detail | Run command | Writes a question for the reporter, if nothing reproduced it. |

**What you'll see:** a couple of tests pass, then one fails with the same wrong total the report describes, and the comment is drafted. Nothing is posted.

**Make it yours:** feed in a real issue (save it as a file in the first step) and replace **Write the next test** with an **Agent** whose goal is "Write one failing test that shows this bug". Keep both **Decide** checks: they stop the agent from claiming success on the wrong failure.

## Keep the README honest

**The pattern:** a loop with the network off. It runs every example in a README, fixes the ones that no longer work, and runs them all again.

```flow
{"title": "Keep the README honest", "nodes": [["setup", "run", "Check out the project"], ["extract", "code", "Pull out the examples"], ["run", "run", "Run every example", "no network"], ["fix", "code", "Fix the stale example"], ["patch", "code", "Write the patch"]], "edges": [["setup", "extract"], ["extract", "run"], ["run", "fix", "Failed"], ["fix", "extract", "Passed"], ["run", "patch", "Passed"]]}
```

| Step | Block | What it does |
|---|---|---|
| Check out the project | Run command | Writes a small library, its README and changelog. |
| Pull out the examples | Run code | Copies each code example out of the README into its own file. |
| Run every example | Run command | Runs them all, with **No internet for this step**. |
| Fix the stale example | Run code | Updates the first broken example to match the changelog, in the README itself. |
| Write the patch | Run code | Writes the README changes as a patch. |

**What you'll see:** the first pass finds two examples that use option names the changelog says were renamed in version 2.0. Each loop fixes one and runs every example again, and the run ends with a patch for the README. Nothing is pushed.

**Make it yours:** clone your project and install it in the first step. Use an **Agent** for **Fix the stale example**, with the goal "Fix the README example that fails, using the changelog to see what changed". Keeping the network off while examples run means a doc example can't reach anything it shouldn't.
