Agent Sandboxes: giving Claude Code a box of its own, per project

claude-code sandboxing nono security homelab agents

Every shell command in this session starts with two lines of noise:

/bin/bash: /etc/bash.bashrc: Permission denied
/bin/bash: /home/metahertz/.bashrc: Permission denied

That’s nono refusing to let the agent read my shell start-up files. The agent is Claude Code, the project is this website, and the whole conversation that produced this post was exported from my Mac a few days ago, uploaded to a Linux box in the loft, and resumed there with its history intact. The box runs Agent Sandboxes, which is what I want to write about.

What I wanted

By October I had agents doing real work: planning runs against the LLM fleet, coding loops on three or four repos at once, and a browser being driven around for research. All of it on my own machines, all of it with tools that could run commands. I’d already walled the models off from the agents. The agents themselves were still a claude process in a terminal, running as me, with my SSH keys, my Docker socket and my home directory.

What I wanted was simple to say. Several projects on one host. Each one’s Claude confined to its own folder. A browser and a desktop the agent could use that weren’t mine. Keys the agent could use without ever reading. A network allowlist per project. And one place to see all of it.

nono does the confinement: Landlock for files, a filtering proxy for the network, cgroups for limits, with a profile format that one profile can extend another. AIO Sandbox is a container with Chromium over VNC, code-server, a shell and an MCP server, which is a very good “other machine” to hand an agent. Agent Sandboxes is the part that ties one of each to a project folder and puts a web UI on top. The first commit was on 22 October. It’s a stdlib Python server and vanilla JavaScript, and much of it was written by Claude Code, increasingly from inside an earlier version of itself.

A workspace’s Claude tab. The session is a tmux pane on the host, Claude is inside nono, and the project folder is the only thing it can write to. Screenshots here are from the demo setup in the repo, with made-up workspaces and keys.

A workspace

A workspace is three things. A project folder, ~/projects/<name> by default. A Claude Code session started by bin/claude-in <name>, which renders that workspace’s settings into a nono profile, prepares its ssh-agent, and runs Claude in a systemd --user scope so memory and process limits apply to its whole tree. And a Docker container, aio-<name>, with the project bind-mounted in, that only that session can reach: nono opens one localhost port per workspace, and Claude’s .mcp.json points at it.

The UI gives each workspace tabs. Claude is the terminal, over a pty, and the session survives closing the browser. Browser is the container’s Chromium over VNC, shared with Claude, so you can watch what it’s doing or take over. VS Code and Terminal are inside the container. Access is where the controls live. Files and Logs are what they sound like.

The Browser tab: the sandbox’s own Chromium over VNC. Claude drives the same session through MCP, and you can reach in with the mouse.

The first hole was Docker

Two days after the first commit I found the first problem, and it’s the kind that makes you glad you looked. The sandboxed Claude could connect to /var/run/docker.sock. I’m in the docker group, the socket is a Unix socket, and Landlock’s file rules don’t stop you connecting to one. Docker socket access is root on the host. The same went for the shared tmux server, which would have let one workspace type into another’s session, and the user D-Bus, where systemd --user will happily run an unsandboxed command for you.

nono has pathname-based AF_UNIX mediation. Turn it on and every Unix socket is denied unless the profile grants it. The profile now grants exactly one per workspace: that workspace’s ssh-agent. No Docker, no tmux, no D-Bus from inside.

The commit message from that day says “root-equivalent” and I meant it. If you confine an agent with a file sandbox and leave sockets alone, you haven’t confined it.

Keys the agent can use but not read

Each workspace gets its own ssh-agent. Keys live in a pool on the host under secrets/, mode 0600, never readable inside nono. Ticking a key for a workspace loads it into that workspace’s agent, live, and unticking it revokes it from a session that’s already running. Claude gets the agent socket and GIT_SSH_COMMAND. It can push to GitHub with a deploy key it has never seen.

The pool. Keys and tokens are stored once and ticked per workspace.

API tokens use nono’s phantom-token proxy. Claude’s environment holds a placeholder, a 64-character hex string, and the proxy swaps the real token in only on requests to that token’s host. The CLAUDE.md notes the UI writes into each project tell the agent as much: “Never ask the user for a real token, and don’t try to print or decode one.”

nono only injects into plain HTTP on loopback, which made http:// APIs on the LAN awkward. A Home Assistant token, say. Those routes go to a small bridge on 127.0.0.2:7100 that relays to the real host, one request per connection with Connection: close both ways, because otherwise nono’s keep-alive could carry one token’s request on to another token’s host. Claude is told to call such APIs through $POOL_<NAME>_BASE_URL, and the UI says plainly that the token crosses the LAN unencrypted.

The network, and what nono can’t do

The allowlist is per workspace. Presets run from minimal (Claude’s own APIs) through claude-code (plus package registries, GitHub, GitLab, docs) to open, with an Also allow box for domains, wildcards and IP addresses, and a Block box that wins over everything.

The Access tab for one workspace: keys, tokens, network preset and extra hosts, the container’s network mode, resource limits, the CLAUDE.md notes toggle, and SSH keys that reach only this workspace.

nono’s proxy filters hosts, not ports. I wanted 10.0.0.5:5432 to mean port 5432 and nothing else. So a workspace with host:port entries gets a small port filter of its own as nono’s upstream proxy. nono checks the host as before and forwards CONNECT host:port; the filter refuses ports the entries don’t list, and also refuses anything that resolves to loopback or link-local. Port changes apply without restarting Claude. Loopback and link-local addresses are refused in the allowlist itself too, because allowing 127.0.0.1 would be allowing the UI.

Only programs that honour HTTPS_PROXY get out. psql and anything else that opens a raw socket stays blocked. That’s a limitation and I’ve left it as one rather than pretend otherwise.

The container’s network was the last piece. By default it’s unfiltered, because Chromium needs the whole web. The alternative, Same as Claude, puts the container on an internal Docker network with no route out, no DNS and no published ports, and runs a second nono proxy for it on the gateway address with the same profile and tokens. Chromium, HTTP(S)_PROXY, Node’s fetch, Python’s requests and pip all point at it. Token hosts work at their real HTTPS URL because the proxy intercepts TLS for those hosts only, with a per-workspace CA whose key never enters the container.

On 29 October the proxies moved out of the UI into their own service, agent-sandboxes-proxy. Until then, restarting the UI to pick up a change dropped every agent’s network connection mid-request. The proxy service has no privileges, a read-only view of the system, and rescans the workspace files every ten seconds. Restarting the UI now costs nothing.

tmux, and SSH that reaches one workspace

The web terminal attaches to tmux, and tmux’s default bindings would let anyone attached open a new window, which is an unsandboxed shell on the host, or switch to another workspace’s session. The prefix and root tables are unbound. You can detach and you can scroll. That’s it. Selecting text in the web terminal takes shift-drag, which is the price.

Keys added under a workspace’s Remote terminal go into authorized_keys with a forced command and restrict. ssh -t attaches to that workspace’s Claude. ssh host shell is a bash inside that workspace’s nono sandbox. Any other command, including rsync and scp, runs there too. The key reaches exactly what Claude in that workspace can reach. The UI refuses a key that already logs into the account unrestricted, because sshd would use that line first.

Moving a project in

This is how this conversation got here. On the Mac:

ssh-keygen -t ed25519 -f ~/.ssh/sandboxes-upload
python3 export-claude-project ~/code/metahertz-website --to metahertz@<host> -i ~/.ssh/sandboxes-upload

The upload key can only rsync into the inbox, with rrsync -wo -munge: no shell, no reading. What goes up is the folder with its .git, .claude/ and CLAUDE.md, minus node_modules and the like, plus the project’s Claude Code sessions, auto-memory, file checkpoints, todos and prompt history, with a manifest sent last so a half-finished upload can’t be imported.

The Import page: an uploaded project in the inbox with its Claude sessions counted, and the upload-key list.

Import moves the folder to ~/projects/<name>, creates the workspace, and installs the history under the new path with the transcript’s working directory rewritten, so /resume and claude -c just continue. Which they did, and here we are.

Two commits this week were about macOS rsync. Apple ships rsync 2.6.9, and from 15.4 an openrsync that sends --dirs to the remote when you ask for -r, which the upload key’s rrsync refuses as invalid syntax. The exporter now tests what the local rsync accepts before uploading and adds --no-dirs for openrsync. Not glamorous. Necessary.

When nono isn’t enough: microVM workspaces

Some work needs more than nono allows. Docker inside the sandbox, root, systemd, or building and running Agent Sandboxes itself. For those, since 2 November, a workspace can be a MicroVM. Claude runs in a KVM guest, QEMU’s microvm machine with Ubuntu’s kernel, as a user with passwordless sudo and Docker, in /project. Only the project folder is shared in, by virtiofsd in its own namespace sandbox. QEMU itself runs under nono on the host with no network and only /dev/kvm, /dev/vhost-vsock and its own files.

The VM has no network interface. Its one channel is vsock. A relay in the guest on 127.0.0.1:3128, which the proxy variables, apt, Docker and ssh all use, connects to the host’s proxy service on vsock port 3128. The proxy service picks the workspace from the guest’s CID, which the host assigns, and hands the connection to that workspace’s nono proxy with the same profile, CA and password a filtered container gets. So the allowlist, the phantom tokens and the per-connection log work the same way whether Claude is in nono or in a VM. Allowlist changes apply at once. The guest can even run its own AIO browser container inside, on Docker’s bridge, everything through the relay.

Watching it

The monitoring stack is Alloy into Prometheus and Loki, with two provisioned Grafana dashboards: every workspace at a glance, and one workspace in detail with its logs. What goes in: an exporter writing per-workspace metrics every 15 seconds (container health, Claude running, policy pending, keys and tokens assigned, limits, project size, the Claude scope’s CPU, memory and OOM kills); cAdvisor for the containers; node exporter for the host; Claude Code’s own OpenTelemetry for tokens, cost, tool use and errors, with prompt and response text redacted; and nono’s audit trail, every connection allowed or denied, tagged with its workspace.

Settings: the UI’s CA for your browser, the monitoring stack’s state, where data goes, retention, Claude Code telemetry, and the editor for the CLAUDE.md notes each workspace gets.

That last source needed care. nono records each token-route request twice, the policy decision before forwarding and the response after, and nono’s audit trail keeps only the first 4,096 connections until exit. The exporter now tails nono’s live log as well, and merges a decision with its response into one record, matched by target, method and path since concurrent requests interleave. The point of all of it is the same as in the fleet post. A deny that nobody sees is a deny that teaches nobody anything.

Backups go to the NAS over SMB on a schedule, pruned by age, with the warning in the UI that the tarball holds private keys and Claude’s login and isn’t encrypted.

What it doesn’t do

The README has a known-gaps section and I’d rather repeat it than have you find out. Every workspace’s Claude shares ~/.claude, so settings, credentials and transcripts are common to all of them, and imported history lands there too. Container egress is unfiltered unless you choose Same as Claude. SSH host keys are trust-on-first-use per workspace. Pool secrets are unencrypted at rest, like ~/.ssh. Telemetry’s workspace label is set by the sandbox, so a workspace could mislabel its own Claude metrics, though nono and container data are labelled from outside. Alloy holds the Docker socket, as any container monitor does. Upload keys log in as my account, with the forced command as the boundary, and one could fill the disk.

And the .bashrc lines at the top of every command are still there. The sandbox denies the shell its start-up files, bash complains, and the work carries on. I’ve stopped noticing.

Where it is

Thirty-one commits since 22 October, three sandbox workspaces and one microVM in daily use, and this post written from one of them. The code is at metahertz/agent-sandboxes. If you run more than one agent on a box you own, I’d start with the Unix socket point, whatever else you do.

← All posts