Skip to content
← All posts · 6 min read

Burner VMs for Coding Agents

Worktrees isolate files, not access. How I run each coding agent in a throwaway microVM, and why the real risk is the code you pull back out.

Bhanu Prakash VemulaAI Lead · AI engineering
LinkedInX
agent-sandbox flow: the host clones a scrubbed copy, the microVM agent edits only that copy and reaches the internet through a deny-all proxy that adds the real token, and its commits return through fetch, a risky-path gate and a staged apply before CI runs them.
Open full size ↗ (opens in new tab)
TL;DR

Worktrees keep agents out of each other's files, not out of yours. Each task now gets a throwaway microVM with a clean copy of the repo, no keys and almost no network. The bigger risk turned out to be the code I pull back out.

My worktrees were isolated. My SSH keys were not.

For months I ran several coding agents in parallel. Each had its own git worktree, its own terminal pane, its own branch. I was quite proud of it.

Every one of them also ran as me. It could read ~/.ssh, my git credentials, my cloud logins and every .env on the laptop.

One gitignored file held Langfuse and OpenAI API keys. Any agent, in any repo, could read it.

So I'd built a very tidy way to hand my credentials to several agents at once.

Nothing got stolen. The worst incident was one session wiping another session's uncommitted work by switching branches in a shared checkout. The agent did exactly what it was allowed to do. It was allowed to do far too much.

HOT TAKE

A git worktree is a folder, not a sandbox. If your agent runs as you, it has your keys.

The fix fits in one line: give the agent the work, not the keys. Here's what that took, and where it still leaks.

The wall is not the weak spot

Most of the risk is in the code you pull back out, not in the sandbox.

Talk about sandboxing agents usually goes straight to escapes. Can it break out of the container? Can it reach the host kernel? Fair questions. Not the likely failure.

The likely failure is boring:

  1. The agent writes a git hook, a postinstall script or an editor config.
  2. I pull the change back and run npm test.
  3. That code runs on my laptop with every credential loaded.

Nobody escaped anything. I carried it out myself, and helpfully ran it too.

So a sandbox is only half the design. The other half is a gate on the way back in.

The setup

Three tools, one job each:

  • Ghostty is the terminal. Where I watch.
  • herdr runs the orchestration: worktrees, panes, which agent is busy or stuck.
  • agent-sandbox is a small private wrapper I wrote around Docker Sandboxes. One throwaway microVM per task.

The life of one task

I hand it a merge request, issue or branch URL plus a short task. Then:

  1. Copy. One commit of tracked files. No history, no remote, no gitignored files. If anything looks like a credential, the run stops.
  2. Boot. A microVM with its own kernel mounts only that copy. No SSH keys, no real tokens.
  3. Lock the network. Only the model API and npm are reachable. Everything else gets a 403, the git host included.
  4. Work. The agent runs headless: implements, checks, reviews its own diff, writes a summary, stops.
  5. Return. Its commits come back as a git ref. The VM and the copy get deleted.
  6. Gate. Anything that would run on my laptop or in CI waits for my sign-off.
  7. Ship. I apply it as one staged patch, or open a draft merge request and let CI run the tests.

Steps 1 and 6 carry most of the design.

Copy, don't mount

The official quickstart hands the agent your .env.

That one surprised me on day one. Docker Sandboxes' mount and clone modes expose gitignored files. The docs say it plainly: "Files such as .env remain readable by the agent."

So I copy instead. A file:// clone only carries tracked files, so the secrets never make the trip. An orphan commit then drops the history and the remote:

git clone --depth 1 --single-branch --branch "$branch" --no-tags "file://$repo" "$copy"
# scrub registry tokens and scan the tracked files for credentials here
git -C "$copy" checkout --orphan "agent/$branch"
git -C "$copy" add -A
git -C "$copy" commit --no-verify -m "sandbox base from $branch"
git -C "$copy" branch -D "$branch"
git -C "$copy" remote remove origin
git -C "$copy" reflog expire --expire=now --all
git -C "$copy" gc --prune=now

The agent sees one commit. No history, no remote, no host .git.

Gate the way back in

Treat every file that can execute as untrusted until a human reads it.

When the agent stops, its branch is fetched into a separate ref, with object checks on:

git -c transfer.fsckObjects=true fetch --no-tags "$copy" "+agent/$branch:refs/sandbox/$name"

Then the gate flags any change that could run on my machine or steer another agent:

  • Agent config: .claude/, CLAUDE.md, AGENTS.md
  • Scripts and hooks: .git*, bin/, scripts/, new symlinks, newly executable files
  • Dependencies: package.json, lockfiles, .npmrc
  • Config that runs code: .env*, *.config.{js,ts,mjs}, CI files, .vscode/

Flagged changes won't apply until I pass --reviewed.

FROM PROD

On a test repo, the gate held back edits to CLAUDE.md, .claude/settings.json and pnpm-lock.yaml. Inside the VM, gitlab.com got a 403. The first real task, a merge request review, ran end to end without me touching the VM.

One gotcha if you test your own network rules: blocked hosts return HTTP 403, so curl still exits 0. Check the status code, not the exit code.

What changed day to day

I stopped babysitting. The agent never asks permission, because there's nothing in the VM worth protecting. I write a task, walk away and come back to a git ref.

Parallel got cheap. A new task is a new VM, not a new risk. Three at once costs RAM, not sleep.

The output reads like a colleague's branch. I get commits, not a chat log or edits scattered through my checkout. I review them the way I'd review anyone's.

Mistakes are disposable. If the agent wrecks the repo, it wrecked a copy I was throwing away anyway.

Where it still leaks

I'd rather list these than have someone find them in the comments:

  • The model API is still open. A prompt-injected agent could send source code out through it with an attacker's key. I accept that; closing it means no model at all.
  • Session tokens. A logged-in agent may hold a real one inside the VM. Not verified yet.
  • Young software. Docker Sandboxes had a critical macOS escape in 2026 (CVE-2026-77179, fixed in 0.42.0). I pin a minimum version.

None of this replaces reading the diff. It changes what reading the diff protects. Before, a bad change could do damage before I saw it. Now the damage stops at a copy, and the diff is the only way back in.

What to check on your own setup

If you run coding agents on your laptop today, start here:

  1. Can the agent read ~/.ssh? Then it can push as you.
  2. Does it see gitignored files? Then it sees your .env.
  3. Can it reach any host it likes? Then it can send your code anywhere.
  4. Do you run its hooks or scripts before reading them? That's the real escape hatch.
  5. Can it edit its own rulebook? Give it a copy of the rules, never the pen.

My worktrees are still isolated. Now my SSH keys are too. My trust issues aren't. Read every diff.

Bhanu Prakash Vemula

AI Lead. I write about the things I ship, with the numbers attached.