Sandboxes
Safety recipes
Five worked examples that put limits and people in the loop: watch a limit stop a runaway loop, get sign-off before shipping, rehearse a database change on a copy, sort support tickets with AI, and take a first look at an alert.
Each recipe below says what it does, shows its shape, walks through its steps, and ends with how to make it your own. See Recipes for how recipes work, and Limits and safety for the protections they use.
Runaway loop
The pattern: a limit stops a loop that would never end. Run this once to see what happens when something goes wrong, so you know what to expect.
| Step | Block | What it does |
|---|---|---|
| Start | Run command | Sets up a job whose check will always fail, like a service that's down. |
| Try again | Run command | Counts the attempt and backs off a little longer each time. |
| Check | Run command | Fails every time: "connection refused". |
| Done | Output | Never reached. |
Limits: 4 loops, 120 seconds, $0.05. If stopped, go back to: Start.
What you'll see: the loop goes round four times, then the run ends as Stopped at a limit, with the loop limit named as the reason. The sandbox is rewound to the checkpoint after Start, so none of the half-finished attempts are left behind. Simulate first and the forecast tells you, before you run, that nearly every run will hit the loop limit.
Make it yours: this recipe is for learning. In your own flows, every loop should have a limit you'd be happy to hit, and a Go back here if a limit stops the run on the last step that leaves things clean.
Fix, review, ship
The pattern: a loop, then a person. The code is fixed automatically, but nothing ships until someone approves.
| Step | Block | What it does |
|---|---|---|
| Set up project | Run command | Writes slugify.py with a bug, and its tests. |
| Run tests | Run command | Runs the tests. |
| Write a fix | Run code | Writes the next fix, then goes back to the tests. |
| Ship it? | Approval | "Ship this fix? The tests pass." |
| Package | Run command | Packs the fix into dist/slugify-fix.tgz. |
Limits: 4 loops, 900 seconds, $0.05. The time is long on purpose, so a person has time to answer.
What you'll see: two fixes, then the tests pass and the run shows waiting. Your team gets the approval email. Approve, and the fix is packaged. Deny, and the run ends at Not shipped.
Make it yours: replace Write a fix with an Agent, and Package with your real deploy command. Add your deploy command to the flow's Policy under Also hold these commands for a person too, so even an agent that tries to deploy early has to wait.
Rehearse a database migration
The pattern: a loop with a restore point, then a person. The change is tried on a copy of the data, checked, undone if anything was lost, and only offered for real once it passes.
| Step | Block | What it does |
|---|---|---|
| Load a sample | Run command | Builds a small shop database, and several candidate migrations. |
| Save a restore point | Run command | Copies the database and records row counts and totals. |
| Run the migration | Run command | Applies the current candidate, with the network off. |
| Anything lost? | Run command | Compares rows and totals with the restore point. Fails if anything is missing or changed. |
| Restore, try the next one | Run command | Puts the data back and moves to the next candidate. Fails if there are none left. |
| Run it for real? | Approval | "The rehearsal passed every check. Run this migration on the real database?" |
| Write the plan | Run command | Writes plan.md with the migration that passed. Nothing runs outside the sandbox. |
Limits: 3 loops, 900 seconds, $0.05. If stopped, go back to: Save a restore point.
What you'll see: the first migration loses data, the check catches it, the data is restored, and the next candidate passes. Then the run waits for a person.
Make it yours: load a recent, anonymized copy of your data in the first step, put your migration in Run the migration, and write checks that matter to you in Anything lost? (row counts, sums of money columns, a few known records). Keep the network off while the migration runs, so a rehearsal can never touch the real database.
Support inbox triage
Needs a Claude key. The pattern: an AI choice with four ways out, and money always waits for a person.
| Step | Block | What it does |
|---|---|---|
| Read the ticket | Run command | Writes a sample customer ticket and the shop's help pages. |
| Sort the ticket | Ask AI, Decision | Claude labels the ticket refund, bug, how-to or spam. The prompt tells it the ticket is text to sort, not instructions. |
| Refund this customer? | Approval | A person reads the ticket and decides. |
| Record the refund | Run command | Writes down the approved refund. No money is moved from the sandbox. |
| Draft a bug report | Run command | Writes the ticket up as a bug report for the team. |
| Draft a reply | Ask AI, Text | Claude writes a short, friendly reply using only what the help pages say. |
| Save the draft | Run command | Confirms the reply was saved. It is not sent. |
Limits: 1 loop, 900 seconds, $0.10.
What you'll see: the sample ticket is sorted, and the run takes that choice's path. Open Sort the ticket to see the choice Claude made, and the tokens and cost (a fraction of a cent).
Make it yours: edit the ticket in the first step to try other kinds, then load real tickets (export them from your help desk, or fetch them with its API), and send the drafted reply back as a draft for a person to review. Keep the Approval on refunds. Change the choices to fit your inbox, and give each its own exit.
First look at an alert
Needs a Claude key. The pattern: gather facts, let AI suggest causes, run checks that can't change anything, and ask a person before the one step that can.
| Step | Block | What it does |
|---|---|---|
| Pull the logs | Run command | Saves the warnings and errors from the last 15 minutes of an app's log. |
| Likely causes | Ask AI, Text | Claude lists the three most likely causes and what to check first. Pass when the reply matches makes sure it's a numbered list. |
| Run read-only checks | Run command | Looks at the app's state, with the network off. Suggests a restart only if a job is stuck. |
| Is a restart needed? | Decide | Yes if the checks suggest a restart. |
| Restart the worker | Run command, Ask a person first | Waits for a person, then restarts. |
| Leave it running | Run command | Notes that nothing was changed. |
| Write the summary | Run code | Writes up the alert, the likely causes, the checks and what was done. |
Limits: 1 loop, 900 seconds, $0.10.
What you'll see: Claude's likely causes, the checks finding a stuck job, and the run waiting before the restart. Whether you approve or deny, the summary is written, because the arrow from the restart uses Either way.
Make it yours: fetch your real logs and status in the first steps, using a saved secret for any API keys so they never enter the sandbox. Keep every check read-only, and keep Ask a person first on anything that changes a system.