quiet robot

Sandboxes

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.

View as Markdown

Sandboxes is in early access. It is free to try, some parts are still in testing, and details may change. Sign up free

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 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.

Fix until tests passSet up project (Run command), Write code (Run command), Run tests (Run command), Fix failures (Run command), Save result (Run command). Arrows: Set up project to Write code; Write code to Run tests; Run tests to Fix failures on Failed; Fix failures to Run tests on Passed; Run tests to Save result on Passed.FailedPassedPassed>_ RUN COMMANDSet up project>_ RUN COMMANDWrite code>_ RUN COMMANDRun tests>_ RUN COMMANDFix failures>_ RUN COMMANDSave result
Fix until tests pass
StepBlockWhat it does
Set up projectRun commandWrites a small project: a slugify function's tests, and four tries at the function.
Write codeRun commandPuts the first try in place.
Run testsRun commandRuns the tests. Passed goes to Save result, Failed goes to Fix failures.
Fix failuresRun commandSwaps in the next, slightly better try, then goes back to Run tests.
Save resultRun commandPacks 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.

Agent fixes the failing testSet up project (Run command), Agent fixes it (Agent), Show the fix (Run command), Fixed (Output). Arrows: Set up project to Agent fixes it; Agent fixes it to Show the fix on Done; Show the fix to Fixed.Done>_ RUN COMMANDSet up project◉ AGENTAgent fixes it12 turns · $0.50 · check: tests>_ RUN COMMANDShow the fix⚑ OUTPUTFixed
Agent fixes the failing test
StepBlockWhat it does
Set up projectRun commandWrites slugify.py with a bug, and its tests. Runs the tests once so you see them fail.
Agent fixes itAgentGoal: 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 fixRun commandRuns 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.

PR reviewerCheck out PR (Run command), Lint (Run command), Run tests (Run command), Write review notes (Run code), Anything to say? (Decide), Post review? (Approval), Post review (Run command), Looks good (Output), Not posted (Output). Arrows: Check out PR to Lint; Lint to Run tests on Either way; Run tests to Write review notes on Either way; Write review notes to Anything to say?; Anything to say? to Post review? on Yes; Anything to say? to Looks good on No; Post review? to Post review on Approved; Post review? to Not posted on Denied.Either wayEither wayYesNoApprovedDenied>_ RUN COMMANDCheck out PR>_ RUN COMMANDLint>_ RUN COMMANDRun tests{ } RUN CODEWrite review notes◆ DECIDEAnything to say?✋ APPROVALPost review?>_ RUN COMMANDPost review⚑ OUTPUTLooks good⚑ OUTPUTNot posted
PR reviewer
StepBlockWhat it does
Check out PRRun commandWrites a small app and a pull request's changes.
LintRun commandA small linter finds an unused import, a bare except and a TODO.
Run testsRun commandRuns the tests and saves what they print.
Write review notesRun codeTurns the findings and test result into a review draft.
Anything to say?Decidetest -s repo/findings.txt: Yes if there are findings.
Post review?Approval"Post these review comments on PR #42?"
Post reviewRun commandSaves 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.

Dependency upgrade botCheck out the app (Run command), List what's out of date (Run command), Fork ×3 (Try in parallel), Patches only (Run command), Patches and minors (Run command), Everything to latest (Run command), Most upgrades, tests pass (Keep the best), Open the pull request? (Approval), Draft the pull request (Run code), Not opened (Output). Arrows: Check out the app to List what's out of date; List what's out of date to Fork ×3; Fork ×3 to Patches only; Fork ×3 to Patches and minors; Fork ×3 to Everything to latest; Patches only to Most upgrades, tests pass; Patches and minors to Most upgrades, tests pass; Everything to latest to Most upgrades, tests pass; Most upgrades, tests pass to Open the pull request? on Passed; Open the pull request? to Draft the pull request on Approved; Open the pull request? to Not opened on Denied.PassedApprovedDenied>_ RUN COMMANDCheck out the app>_ RUN COMMANDList what's out of dateno network⑂ TRY IN PARALLELFork ×3Patch, Minor, Latest>_ RUN COMMANDPatches onlyLane Patch>_ RUN COMMANDPatches and minorsLane Minor>_ RUN COMMANDEverything to latestLane Latest★ KEEP THE BESTMost upgrades, tests passhighest upgraded✋ APPROVALOpen the pull request?{ } RUN CODEDraft the pull request⚑ OUTPUTNot opened
Dependency upgrade bot
StepBlockWhat it does
Check out the appRun commandWrites an app with three libraries and passing tests.
List what's out of dateRun commandLists available upgrades, with the network off.
Patches only, Patches and minors, Everything to latestRun command, one per laneEach lane applies its plan and runs the tests, printing how many libraries it upgraded.
Most upgrades, tests passKeep the bestKeeps the lane with the highest upgraded count whose tests passed.
Open the pull request?ApprovalA person decides.
Draft the pull requestRun codeWrites 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.

Reproduce a bug from an issueCheck out the code (Run command), Write the next test (Run code), Does the test pass? (Decide), Fails as described? (Decide), Draft the repro comment (Run command), Ask for more detail (Run command). Arrows: Check out the code to Write the next test; Write the next test to Does the test pass? on Passed; Write the next test to Ask for more detail on Failed; Does the test pass? to Write the next test on Yes; Does the test pass? to Fails as described? on No; Fails as described? to Draft the repro comment on Yes; Fails as described? to Write the next test on No.PassedFailedYesNoYesNo>_ RUN COMMANDCheck out the code{ } RUN CODEWrite the next test◆ DECIDEDoes the test pass?no network◆ DECIDEFails as described?>_ RUN COMMANDDraft the repro comment>_ RUN COMMANDAsk for more detail
Reproduce a bug from an issue
StepBlockWhat it does
Check out the codeRun commandWrites a shopping cart module and a bug report about a coupon.
Write the next testRun codeWrites one more small test. Fails when it has no ideas left.
Does the test pass?DecideRuns it with the network off. If it passes, the bug didn't show: try another test.
Fails as described?DecideChecks the failure matches the report. If not, it's a different problem: try another.
Draft the repro commentRun commandWrites a comment with the test that shows the bug.
Ask for more detailRun commandWrites 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.

Keep the README honestCheck out the project (Run command), Pull out the examples (Run code), Run every example (Run command), Fix the stale example (Run code), Write the patch (Run code). Arrows: Check out the project to Pull out the examples; Pull out the examples to Run every example; Run every example to Fix the stale example on Failed; Fix the stale example to Pull out the examples on Passed; Run every example to Write the patch on Passed.FailedPassedPassed>_ RUN COMMANDCheck out the project{ } RUN CODEPull out the examples>_ RUN COMMANDRun every exampleno network{ } RUN CODEFix the stale example{ } RUN CODEWrite the patch
Keep the README honest
StepBlockWhat it does
Check out the projectRun commandWrites a small library, its README and changelog.
Pull out the examplesRun codeCopies each code example out of the README into its own file.
Run every exampleRun commandRuns them all, with No internet for this step.
Fix the stale exampleRun codeUpdates the first broken example to match the changelog, in the README itself.
Write the patchRun codeWrites 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.