Agent Sandboxes, part two: building it from inside itself
A week ago I wrote about Agent Sandboxes, the setup on a Linux box in my loft that gives each of my Claude Code projects a box of its own. MicroVMs got a short section right at the end of that post, almost as an afterthought. Since then they’ve become the bit I use most, because they’re now how Agent Sandboxes itself gets built: by Claude, in a workspace that Agent Sandboxes runs.
Which raises a pretty obvious question…
If the agent is writing the code for its own sandbox, what stops it loosening the sandbox?
Short answer: it doesn’t get to deploy it. Longer answer, read on!
Why a VM at all?
A normal workspace is Claude running inside nono, directly on the host. That’s a great boundary for most projects, but it rules a lot out. No Docker (the Docker socket is root on the host, so that’s a hard no), no sudo, no systemd, no installing packages, nothing that wants its own tmux.
For most of my projects that’s fine. For Agent Sandboxes, which is basically systemd units, compose files, tmux configs and a Python server, that’s… nearly everything. Not ideal.
What a microVM workspace can do
A microVM workspace moves the boundary out a level. Claude runs in a KVM guest (QEMU’s microvm machine type, with Ubuntu’s kernel) as a user called dev, with passwordless sudo and Docker. Inside the VM it can pretty much do what it likes:
sudo apt installwhatever the project needs.- Run Docker, build images, bring up compose stacks.
- Run systemd services, its own tmux, and servers on whatever port it wants.
- Run its own AIO browser container (Chromium, VS Code, a terminal), which shows up in the UI’s Browser, VS Code and Terminal tabs the same as any other workspace.
What it can’t do is leave. The project folder is the only thing shared in, mounted at /project by virtiofsd, which itself runs in its own namespace sandbox. Each VM gets its own disk, copied from a base image that bin/microvm-image builds from Ubuntu’s archive (no root needed). And on the host, QEMU itself runs under nono, with no network and access to only /dev/kvm, /dev/vhost-vsock and its own directory.
The networking is the bit I’m happiest with. The VM has no network interface at all. Its only way out is vsock. A little relay inside the guest listens on 127.0.0.1:3128, and everything that talks to the network gets pointed at it: the proxy environment variables, apt, Docker, git, ssh’s ProxyCommand. The relay hands connections over vsock to the host’s proxy service, which works out which workspace it is from the guest’s CID (assigned by the host, so the guest can’t fake it) and passes the connection to that workspace’s nono proxy.
The upshot is that a microVM gets exactly the same allowlist, the same phantom API tokens and the same per-connection audit log in Loki as every other workspace. Change the allowlist in the UI and it applies immediately, nothing to restart in the guest.
SSH keys work the same way too. The Claude tab opens Claude inside the guest over vsock ssh, with the workspace’s ssh-agent forwarded, so git over ssh uses whichever keys I’ve ticked for that workspace, through the proxy. The private keys never go anywhere near the VM.
Bonus: this also closes one of the gaps I owned up to last time. Every sandbox workspace shares the host’s ~/.claude (settings, credentials, history, the lot). A microVM’s Claude installs itself on first boot and keeps all of that inside the VM.
This week the VMs also got proper sizing. The Access tab now sets vCPUs (up to however many the host has) and disk size (16G by default, up to 4T, as a sparse file that grows when the VM starts) as well as memory. The browser container inside gets its own memory and CPU limits too, and the UI checks they actually fit inside the VM, rather than letting you find out the hard way later. Disks only grow, though, so asking for less than you’ve already got gets refused.
First job: git push (or not)
The very first real job I gave a microVM was Agent Sandboxes’ own repo. The very first thing that broke? Pushing.
Two bugs, both the day after microVMs landed:
- HTTPS pushes died with “Proxy CONNECT aborted”. It turns out git asks a proxy which auth method it wants by waiting for a
407… and nono’s proxy never sends one, it just expects the credentials up front. Stalemate. The fix was settinghttp.proxyAuthMethod=basicsystem-wide in the guest, so git sends them on the first request. - ssh refused to read its own config with “Bad owner or permissions”. The image builder, mmdebstrap, had helpfully copied the owner of every staged path into the image, so
/,/etcand/etc/sshall belonged to uid 1000. Which, in the guest, isdev. Oops! A hook now hands everything back to root.
Neither of these would have shown up in a quick test, you only find them by actually trying to do real work in the thing.
Developing Agent Sandboxes… in Agent Sandboxes
The groundwork for this actually started a day earlier, with listen ports. Until then a sandboxed Claude couldn’t run a server at all; nono’s generated profile didn’t grant any listen_port, so every bind just failed. No dev servers, and definitely no running a test copy of the UI and proxy from inside a workspace. The commit message for per-workspace listen ports even says it: “the first step towards developing agent-sandboxes in one of its own workspaces”.
There’s a catch, as always. nono’s listen_port can’t be tied to an address, so a granted port binds on every interface. That’s why the UI refuses any port Agent Sandboxes uses itself (the sandbox ports, port filters, the API bridge, Alloy’s collector). If a workspace could grab one of those while the real service was down, it could stand in for it and receive another workspace’s MCP connections, which carry that sandbox’s API key. Not great! It also won’t hand out a port another workspace already has.
With listen ports and microVMs both in place, the loop looks like this:
- The
agent-sandboxesworkspace is a microVM, with its own clone of the repo in/project. - Claude works in there. It installs what it needs, runs a test copy of the UI and proxy service, and drives them in the VM’s own Chromium to check the page actually renders.
- It commits and pushes to GitHub using a deploy key from the pool, which it can use through the forwarded agent but never read.
- The copy the host actually runs is a completely separate checkout in
~/agent-sandboxes, and nothing in any workspace can write to it.
Every commit in the repo is now co-authored by Claude, and this week’s (the resource limits, the Host page and the sign-in changes further down) were all written from inside the very thing they change. Which is still slightly mind-bending to me, if I’m honest.
The step Claude doesn’t get to take
Step four is the important one. The code that decides what a sandbox is allowed to do lives in the UI’s profile renderer, the proxy service and the nono profile. Changing that code is Claude’s job. Making it the code that actually runs is mine.
Until this week, my half of that was clunky. SSH into the host, git pull, then squint at the diff to work out what needed reinstalling or restarting. A systemd unit? The nono profile? A tmux config? The proxy? Just the UI? It was really easy to get wrong, and I’d find out later when the UI’s journal told me the proxy was still running old code SadFace.
So now there’s a Host page in the sidebar (just above Settings), with a script behind it.
The page is a login shell on the host, as me, sat in ~/agent-sandboxes. It runs in its own tmux server, separate from the locked-down one the Claude sessions and workspace SSH keys attach to, and it survives you leaving the page or restarting the UI. That second part matters more than it sounds, because restarting the UI is one of the main things you do from it! The header shows the checked-out commit and whether the UI or proxy is running older code than what’s on disk, and there are four buttons that just type a command into the shell for you: Update from git, Restart UI, Restart proxy and Service status.
The Host page. A real shell on the host, and a little green pill telling me everything’s running the code on disk.
Update from git runs bin/update-host, which does the squinting at the diff for me:
git pull --ff-only, so if history has been rewritten it fails loudly rather than quietly merging.- Prints the new commits, so I can see what I’m about to run.
- Reinstalls only the systemd units and nono files that have actually changed, and reloads the tmux configs if they did.
- Restarts the proxy service only if its code changed, because that drops every sandbox’s open connections.
- Restarts the UI last; the page reconnects a few seconds later.
- Anything slow or that needs a decision (a new AIO image pin, changes to the microVM guest image) it just tells me about, and leaves to me.
There’s an --all flag to apply everything regardless, for after a manual pull.
One bit was fiddlier than expected. The UI’s service runs with NoNewPrivileges, so any shell it starts can never use sudo, and update-host needs sudo to install units. So the shell gets started by my systemd --user instance instead (systemd-run --user --pty), outside the service, where sudo works fine. If there’s no user instance (lingering’s off), it falls back to a child of the service, the page warns you sudo won’t work, and update-host stops with instructions rather than half-applying an update and leaving things in a mess.
So why split it this way?
Basically, I’ve drawn the line where the privilege is.
Claude in the microVM has root, but only inside its own VM. It can write whatever it likes for Agent Sandboxes, test it and push it. What it can’t do is get that code onto the host. No write access to ~/agent-sandboxes, no route to the host’s systemd, and no way to restart the proxy that’s filtering its own traffic.
If Claude ever wrote a change to the profile renderer that quietly widened every sandbox, it would sit in GitHub until I ran
update-host… andupdate-hostshows me the commit log first.
I hold the other half. The Host page is a full, unsandboxed shell as my user, and I’m in the docker group, so let’s be honest, it’s effectively root. That’s deliberate, it’s my tool, not Claude’s, and no workspace has a route to it. Anyone who can sign in to the UI gets it too (the README is very upfront about that), which is a big part of why sign-in changed this week. If you’d rather not have that exposure at all, AIO_HOST_SHELL=0 in the UI’s unit turns the page off.
To be clear, none of this reviews the code for me. update-host will happily apply whatever’s on the branch. The point is that running new code on the host is a separate, visible step that a human takes, and the tooling makes that step quick enough that I don’t skip reading the log. Same idea as the rest of the project really: let the agent do loads, inside a boundary it can’t move.
Other new features
Signing in with a password or a passkey! Until this week the only way into the UI was a token in a link, and the cookie it gave you never expired and couldn’t be signed out. Fine for a toy, but not for something that now hands out a root-equivalent shell on its Host page.
It’s still one account, the user the UI runs as, but you now sign in with that user’s normal system password (checked by PAM) or a passkey. Nobody else on the box can sign in, even with their own password; other usernames never even reach PAM.
PAM had exactly the same snag as the Host page. NoNewPrivileges blocks PAM’s setgid password helper (unix_chkpwd), so every password check would just fail. Same fix: the check runs from my systemd --user instance via a small ctypes libpam client, and if there isn’t one, the sign-in page tells you why instead of rejecting every password and leaving you confused.
Passkeys get added under Settings → Sign-in, and only if you’ve typed the password in the last ten minutes, so a long-lived session, or one opened with the old token link, can’t add one on its own. Add as many as you like: iCloud Keychain, Google Password Manager, 1Password, a hardware key, and a phone can sign in a laptop by QR code. Only the public keys are stored, and signatures are checked with the openssl CLI plus a tiny CBOR decoder, so no new Python dependencies (which I was quite pleased about). One gotcha: passkeys are bound to a hostname and browsers won’t use them on a bare IP address, so the UI explains that if you try.
Sessions are now random cookies, stored hashed on the server, lasting a week idle or 30 days max. They survive UI restarts, and you can sign out (including Sign out other sessions). Failed sign-ins are rate-limited, 5 per address in 15 minutes and 20 in total. The token link still works as a break-glass way in, and AIO_TOKEN_LOGIN=0 turns that off. And yes, update-host installs the new PAM service file, so this landed on the host exactly the same way as everything else in this post.
Uploads in the Files tab. It could only browse and download before. Now you can upload files and whole folders, by button or just dragging them onto the list, into whatever folder you’re looking at, including a microVM’s browser container. Each file goes to a hidden temp file first and only gets renamed into place once its size matches, so a cancelled upload never leaves a half-written file lying around, and it asks before replacing anything that’s already there.
TL;DR
Thirty-five commits since 22 October. This week’s were written by Claude in a microVM and applied by me from the Host page. The code’s at metahertz/agent-sandboxes.
If you’re letting an agent work on its own infrastructure, I’d keep the step from “pushed” to “running” on your side of the line, and make that step easy enough that you actually take it every time.
Happy hacking!
-Matt