03/ 03Case study
Autonomous Repository Engineer
A verified tool-using coding agent: the model only proposes tool calls, a deterministic state machine decides, code the agent writes runs in a sandbox, and completion requires the runtime's own passing tests.
- Python
- Docker
- MCP
- pytest
- uv
Lab/See it run
ANALYZEThe runtime inventories the target repo - file tree, tests, entry points - fully inside the workspace jail. The planner sees only the summary.
01/Overview
What this is.
repo-engineer is a coding agent whose model only proposes. Every tool call, from the native tool-calling planner or an MCP client, is validated and permission-checked before it runs, and every path argument is confined to the workspace; tests run in a sandbox; and a task is accepted only when a re-run of the restored, protected tests exits 0.
The project treats agent reliability and safety as runtime engineering rather than prompting: malformed calls, shell access, workspace escapes and unverified success claims are each handled by a mechanism with a regression test, and an adversarial attack suite tries to break all of them.
02/Problem
What motivated it.
Coding agents tend to fail in three ways: they break on a malformed tool call, they hand the model a shell, or they accept the model's word that the bug is fixed. And once an agent can write tests and run them, it can run arbitrary code.
The gap this project attacks: where does the security boundary live when the model is untrusted? Here it lives in the runtime and the sandbox, never in the model, and every claim about it is backed by an attack that tries to break it.
03/System
How it is built.
- state.py
- A nine-state machine (INIT, ANALYZE_REPO, PLAN, ACT, OBSERVE, REPLAN, VERIFY, COMPLETE, FAILED) with an explicit transition table; any other edge raises. Step, replan and planner-error budgets end in FAILED.
- tools.py
- Ten built-in tools (list_tree, search, read_file, find_symbol, repo_map, apply_edit, apply_patch, write_file, git_diff, run_tests) behind schema validation, AUTO/ASK/DENY policies and the path jail. run_tests accepts only python -m pytest with allowlisted flags.
- sandbox/docker.py + local.py
- Docker: a fresh container per test run with no network, read-only root and workspace, tmpfs-only writes, all capabilities dropped, a non-root user and resource limits. Local fallback: scrubbed environment, POSIX rlimits or a Windows job object, and a process-tree kill.
- native_planner.py + models/
- Native tool calling for Gemini, OpenAI, Anthropic and local OpenAI-compatible servers through one retry policy with SDK retries off; a planner-owned finish tool sends the run to VERIFY.
- mcp_server.py + mcp_tools.py
- MCP both ways: the registry is served over MCP with the same gates, and external MCP servers start inside the sandbox with their tools registered under the same validation, policy, jail and trace.
- patch.py + repo_map.py
- Strict unified-diff patches written all or nothing across files, and an ast-based symbol index with a ranked, size-limited repo map for the planner.
- trace.py + replay.py
- A streamed JSONL audit trace (states, model calls with latency, tokens and cost, tool calls, verification) and a replay command that re-executes recorded decisions without calling a model.
04/Approach
The mechanisms that matter.
Planner proposes, runtime disposes
Planner output is only a tool-call proposal. The state machine alone transitions states, enforces budgets and decides verification, so it is the auditable safety boundary.
Argv parsing, not string prefixes
The old allowlist was a string prefix, so python -m pytestfoo or pytest's -p, -c and --rootdir flags could run code outside the workspace. Commands are now parsed with shlex against a flag allowlist, and the runtime always adds --rootdir, --confcutdir and -p no:cacheprovider.
Exit codes, not output text
Verification used to look for exit=0 in output the tests control. It now uses the structured exit code, restores protected test files before VERIFY, and treats zero collected tests as a failure.
Mutants for test-writing tasks
On add-a-test tasks, seeded mutants must fail and behavior-preserving edits must pass, so a vacuous test cannot complete the task.
No git subprocess
git_diff used to run git, which honours config inside the workspace (fsmonitor, textconv). It is now an in-process diff against a snapshot taken at the start.
Secrets stay out
Test subprocesses get an explicit environment allowlist, and secrets and host paths are redacted from traces and prompts.
05/Evaluation
Setup and workloads.
- Scripted benchmark: 12 multi-file tasks (bug fixes, tests checked with mutants, renames, refactors, signature changes), each run in a fresh workspace copy with recipes that already contain the fix. Results must match the committed goldens byte for byte under both sandboxes.
- Jail suite: scripts/run_jail_attacks.py replays hostile tool calls against a real registry and sandbox. Each attack is rejected, contained, a documented residual or breached, and any breach fails the tests.
- Live mode reports pass@1 and pass@k with the unbiased estimator; no live run with the native planner has been recorded yet.
06/Results
Measured outcomes.
- 0
- breaches in 49 attacks on the Docker sandbox; 1 residual, a forged test report
- 12/12
- multi-file tasks, scripted, byte-identical under both sandboxes
- 10
- built-in tools behind schema, policy and path jail
- 380
- tests, plus jail suites that must reproduce exactly
| Task | Steps | Replans | Failed calls | Files changed |
|---|---|---|---|---|
| Fix an off-by-one loop | 5 | 0 | 0 | 1 |
| Repair a failing test | 5 | 1 | 0 | 1 |
| Add missing tests (mutants) | 5 | 0 | 0 | 1 |
| Constrained rename | 7 | 0 | 0 | 2 |
| Bug behind another module | 6 | 1 | 0 | 1 |
| Rename across a package (one patch) | 5 | 0 | 0 | 3 |
| Add tests for a parser (mutants) | 4 | 0 | 0 | 1 |
| Extract a shared helper | 4 | 0 | 0 | 3 |
| Signature change and its callers | 4 | 0 | 0 | 2 |
| Shared mutable default | 5 | 1 | 0 | 1 |
| Add tests for a validator (mutants) | 4 | 0 | 0 | 1 |
| Stale imports after a move | 4 | 0 | 0 | 2 |
Scripted mode, from results/benchmark_results.json: 12/12 verified, 58 steps, 3 replans, 0 failed tool calls. The recipes already contain the fix, so this validates the runtime, gates, sandboxes and verification, not a model's problem solving. Jail suite (results/jail_attack_evidence*.json): Docker 49 attacks, 29 rejected, 19 contained, 1 residual (report forging), 0 breached; local 47 attacks, 29 rejected, 13 contained, 5 documented residuals, 0 breached.
07/Findings
What the results say.
- 01
The boundary holds under attack on Docker: 49 hostile tool calls produced 29 rejections, 19 contained runs, 1 documented residual and 0 breaches.
- 02
The remaining residual is report forging: code under test can write a passing JUnit report and exit 0 inside its own process, which no sandbox can prevent. Protected tests, mutants, neutral edits and human review are the defences.
- 03
Without Docker the local backend still has 0 breaches over 47 attacks, but agent-written test code runs as the host user, so 5 residuals are documented rather than hidden.
- 04
Every security fix started as a reproduced exploit: a regression test showed the allowlist bypass, the git_diff hijack, verification spoofing and secret leakage before each was closed.
- 05
12/12 scripted tasks verify with 0 failed tool calls and byte-identical results under both sandboxes. That shows the runtime is deterministic; it says nothing yet about a model's skill.
08/Decisions
Why it was built this way.
A state machine around the planner
The planner is the only non-deterministic component; wrapping it makes the safety boundary auditable and identical for every planner.
Security in the runtime, not the model
The model only proposes; validation, permission policy, the jail and the container decide. Prompting is never the safety boundary.
Docker CLI with a local fallback
One container per test run is simple to reason about; the local backend keeps the tool usable without Docker, with its weaker threat model written down.
Native tool calling, JSON as fallback
Schema-constrained arguments and call ids cut parse failures and make multi-step bookkeeping exact; one retry policy covers every provider.
Strict all-or-nothing patches
A unified diff must match exactly or at one unique offset, never with fuzz, and multi-file writes roll back together.
stdlib ast for the repo map
The target repos are Python, so ast gives symbols with zero dependencies, and parse failures are listed instead of fatal.
09/Validation
How the claims are checked.
- 380 tests pass with ruff and pyright clean, including a regression test for each audited exploit that reproduced it before the fix.
- Both jail suites rerun in the tests and must match the committed evidence exactly; any breach fails the build.
- The scripted benchmark must reproduce its golden results byte for byte, and every generated number in the README, report and demo site is checked against results/ by sync_docs.py --check.
- The state machine is exhaustive: any transition outside the table raises, so COMPLETE is reachable only through VERIFY.
10/Limitations
Stated plainly.
- Live pass@k with the native planner has not been measured; the scripted benchmark validates the runtime, not a model.
- No sandbox makes a verdict trustworthy against code written to fool it, such as forged reports or objects that compare equal to anything.
- Without Docker, agent-written test code runs as the host user with the host's files and network, and some processes can outlive the tree kill.
- The repo map is Python only, and tests that need third-party packages need their own sandbox image.
- The CI workflows are written but have not run on GitHub yet; the same gate runs locally.
11/Summary
- Built
- A coding agent whose model only proposes tool calls: a nine-state machine validates and permission-gates every call and jails every path argument, tests run in a Docker sandbox, and a task is accepted only when a re-run of the restored, protected tests exits 0.
- Why
- Coding agents break on malformed calls, hand the model a shell, or trust its claim of success, and once they can write and run tests they also run arbitrary code. This runtime treats each of those as a design constraint.
- How it works
- The planner proposes a native tool call; the runtime validates it against the tool's schema, applies the AUTO/ASK/DENY policy and the path jail, runs tests in the sandbox, and VERIFY re-runs the suite on restored files before COMPLETE.
- Key decision
- Putting the security boundary in the runtime and the sandbox instead of the model, and backing it with an attack suite rather than an argument.
- Strongest result
- 0 breaches across 49 attacks on the Docker sandbox with 1 documented residual (code under test forging a passing test report), and 12/12 multi-file tasks verified byte-identically under both sandboxes.
- Main limitation
- Live agent capability is not measured yet: the 12/12 is scripted, so it proves the runtime, not problem solving.
- Next
- A live pass@k run with the native planner, and the first CI run on GitHub.
Common questions
Q01Where is the security boundary?
In the runtime and the sandbox, never in the model. The LLM only proposes; validation, permission policy, the jail and the container decide.
Q02The agent can write tests and then run them. Isn't that arbitrary code execution?
Yes, which is why tests run in a no-network, read-only container with resource limits. On the local backend this is a documented residual, and the threat model is explicit per backend.
Q03How do you stop reward hacking?
The exit code, not output text; protected files restored before VERIFY; control files such as conftest and pytest.ini unwritable; and mutants for test-writing tasks, so a vacuous test fails.
Q04Why native tool calling over JSON in the prompt?
Schema-constrained arguments, call ids for multi-step bookkeeping and fewer parse failures. JSON parsing stays as a fallback.
Q05What does 12/12 prove?
That the runtime, gates, sandboxes and verification work end to end with known recipes. Agent capability needs the live pass@k run, which has not been done yet.