Most of the time spent on a bug goes into reproducing it. The issue says “export breaks with unicode filenames”; somebody has to work out which export, which filenames, on which version, and write it down as something that fails on demand. That step is a good fit for an agent: it is tedious, it is checkable (the test either fails for the stated reason or it does not), and its output is small enough for a person to review.
It is also risky. The input is text written by anyone who can open an issue, and the agent’s job is to run code based on it. This post describes a design that keeps the useful part and contains the risky part.
What the agent produces
One artefact: a patch that adds a test which fails on the current main branch, plus a short explanation of what it shows. Optionally, a second patch with a fix that makes the test pass.
Not a merged change, not a comment posted on the issue, not a pushed branch. A person reviews the patch and decides. Keeping the output to a patch means the agent never needs write access to anything outside its sandbox.
The environment
Each reproduction attempt runs in its own sandbox, started from a snapshot of the repository with its dependencies installed.
- Build the snapshot on a schedule. A job checks out main, installs dependencies, runs the test suite once to confirm it is green, and calls
sandboxes.snapshot. The snapshots guide says a snapshot is an archive of the sandbox’s/workspace, checked end to end, and that runtime secrets are never in it because nothing mounted into the workspace is included. - Start each attempt from it.
sandboxes.create({ snapshotId, timeoutSeconds, labels: { issue: '1234' } }). Every attempt begins from the same known-good state, so “the test fails” means something. - No network by default. The SDK’s
networkoption defaults tonone. Reproducing a bug in your code rarely needs the internet, and an issue that tries to persuade the agent to download a “helper script” gets nowhere. If some reproductions do need a registry, use your organization’s allowlist, not open egress. - No credentials. The box needs none. It reads the repo, runs tests and writes files. Anything that needs a token, such as fetching the issue text, happens in your orchestrator, outside the sandbox.
The loop
- Your orchestrator fetches the issue and strips it to the text: title, body, and any code blocks. It records where the text came from.
- It starts a sandbox from the latest snapshot.
- The agent works through tools that act only on that sandbox: run a command, read a file, write a file. The run_code tool schema post covers how to describe and limit those.
- The agent writes a test in the project’s own test framework and runs it. It should fail, and fail for the reason the issue describes.
- The orchestrator checks the claim. It runs the new test itself, in the same box, and checks the exit code and that the failure message relates to the issue. It also runs the rest of the suite to make sure the agent did not break anything else to make its test fail.
- It extracts the patch with
git diff, stops the sandbox, and files the patch for review. Checking an agent’s patch before applying it covers what to look for.
Step 5 is the important one. “The agent says it reproduced the bug” and “a test fails” are different statements. Only the second should reach a person’s review queue.
Treat the issue as hostile input
Issue text is untrusted. It can contain prompt injection aimed at your agent, and it can contain hidden Unicode that a reviewer will not see. The controls:
- The sandbox is the blast radius. Whatever the issue persuades the agent to run, it runs in a microVM with no network, no secrets and a time limit. That is the whole reason to do this in a sandbox rather than on a CI runner with tokens.
- The output is reviewed text. A patch is something a person reads before it does anything. Make the review show the diff with invisible characters made visible.
- No side channels out. The agent’s only output is the patch and its explanation. It does not post comments, open pull requests or call webhooks. If you later want it to comment on the issue, have your orchestrator post a fixed template with a link, not free text from the model.
- Rate limit per author. One person opening fifty issues should not get fifty sandboxes. Cap attempts per issue and per author in the orchestrator.
Limits and failure modes
- Time. Set
timeoutSecondson create to bound the whole attempt, and a shorter time limit on each command. A reproduction that needs longer than your limit is a candidate for a person anyway. - Resources. The run result reports
oomKilledandtimedOut. A bug that only reproduces under memory pressure is real; record those flags so a reviewer can tell “test fails” from “box ran out of memory”. - Flaky reproductions. Run the failing test more than once. If it fails only sometimes, say so in the report rather than presenting it as a clean reproduction.
- Nothing reproduced. That is a useful result too. “Tried these three things on main at this commit; all passed” saves a maintainer time.
What it costs to run
Each attempt is one sandbox for as long as the attempt takes. The plans reference says hours are awake vCPU-hours and a box counts only while it is awake, so stopping the box as soon as the patch is extracted keeps each attempt’s cost bounded by its own work. Your plan’s boxes-at-once limit (3 on Free, 30 on Pro and Team) caps how many attempts run in parallel; queue the rest.
Where it fits
This sits well next to triage: a maintainer labels an issue “needs repro”, the agent tries, and the maintainer gets either a failing test or a note saying what was tried. It does not replace the maintainer’s judgement. It removes the most mechanical part of the job and does it somewhere a malicious issue cannot hurt anything.