firecode

deadtrickster/firecode Checked 3 days ago

Firecracker and libvirt sandboxes for coding agents - layered rootfs, 60ms checkpoint restores, a verify gate that decides done, and a way to talk to a run in…

Run a coding agent inside a Firecracker microVM, so you can walk away from it. The agent gets root, the network, and your project - at the same path it has out here. It does not get your host: no host filesystem, no host processes, no host devices. It runs with permission checks off, because there is nothing in there worth protecting. When it finishes, the work is copied out to a sibling directory. Your project directory is never written to. A run is not a black box, and "done" is not the agent's opinion:

Summary extracted from the README.

firecode

Run a coding agent inside a Firecracker microVM, so you can walk away from it.

cd ~/Projects/thing
firecode claude "port the parser to the new AST and make the tests pass"

The agent gets root, the network, and your project - at the same path it has out here. It does not get your host: no host filesystem, no host processes, no host devices. It runs with permission checks off, because there is nothing in there worth protecting. When it finishes, the work is copied out to a sibling directory. Your project directory is never written to.

A run is not a black box, and "done" is not the agent's opinion:

firecode claude --deliver ~/Projects/thing --verify './run-tests.sh' \
  -- -p 'build the thing, tests and all' --dangerously-skip-permissions

--verify is run by the harness after the agent exits, in the project as it will be handed over. Its exit status is the run's. Meanwhile firecode logs -f shows what it is doing, firecode say puts another turn into it, and the agent inside can ask you a question and wait for the answer.

What it protects against

Wiping your system, and reading things it has no business reading - SSH keys, GPG keys, browser profiles, cloud credentials. The guest has no path to any of them: it sees a copy of one project and nothing else of yours. --add-dir refuses outright to carry .ssh, .gnupg, .aws, .kube, .docker, .config/gh, .password-store, .netrc, npm/cargo/gcloud/azure credentials or a browser profile out of your home directory, and so does --workdir - a directory containing one of those is refused the same way, so --add-dir ~ cannot carry them in either. Your own list goes in ~/.config/firecode/never-share, one path or glob per line.

It does not protect your API credits or your network. The agent has your Claude credentials, because otherwise it cannot work - unless you run with --auth-relay, which authenticates through this host and leaves the VM holding none.

Install

Needs Linux with KVM and e2fsprogs. docker is needed once, to build the first guest image; after that firecode builds its own.

sudo usermod -aG kvm,docker "$USER"        # then log back in

firecode setup                             # firecracker, jailer, guest kernel
firecode prepare --with "dotnet@10 uv"     # first guest image, via docker
firecode doctor                            # check the host is ready

On a Mac

Apple silicon and macOS 14 or later. For step-by-step setup from a bare Mac - including putting firecode on PATH and driving it from letibot - see letibot's firecode-on-macos.md; what follows is what is different here and why. There is no KVM, so no firecracker: the VMM is firecode-vz, a small Swift program in macos/ over Apple's Virtualization.framework that speaks firecracker's config file, API socket and vsock protocol - everything above it is the same code. The guest is arm64 Ubuntu, and needs no docker and no root at any step:

xcode-select --install                     # swiftc, to build firecode-vz
brew install bash coreutils gnu-sed findutils gawk grep e2fsprogs \
  socat flock rsync tmux zstd python@3.13

ln -sf "$PWD/bin/firecode" /opt/homebrew/bin/firecode   # on PATH; links resolve
firecode setup                             # builds firecode-vz, fetches the arm64 kernel
firecode prepare --with "uv"               # first image, built in a VM
firecode doctor

firecode setup compiles firecode-vz and ad-hoc signs it with the com.apple.security.virtualization entitlement - a local signature, no certificate or Apple account. The kernel is Ubuntu's arm64 generic one: under Virtualization.framework every device is on PCI, which firecracker's kernels do not support. prepare boots Ubuntu's minimal base tarball in a VM and runs the same guest/build-rootfs.sh as prepare --in-vm.

What is different, and why:

Linux macOS
a tap and a /30 per VM, iptables NAT vmnet's NAT; the guest takes an address by DHCP, and keeps it run to run because its MAC is derived from the project
the jailer none - the machine runs in Apple's own sandboxed Virtualization XPC service, not in firecode-vz
cgroups for lifetime the same tree kept as files under .cgroup/, pid plus start time, so a recycled pid never reads as a live run
the host's claude binary a linux-arm64 build of the same version, fetched and checksummed into vendor/guest/
~/.claude/.credentials.json read from the login Keychain (macOS may ask once whether security may)
firecode chat install as a systemd user unit a LaunchAgent

Nothing needs net-setup or install-privileged.sh; both say so and exit.

The guest is arm64, and x86 still runs in it. qemu-user is registered with binfmt_misc, so a 386 or amd64 binary - GOARCH=386 go test ./..., an amd64 container image - runs transparently under emulation instead of failing with "exec format error". Slower than native, and fine for tests.

Not available on a Mac: --gpu and --vmm libvirt (no passthrough), hardware counters in a guest, pinning to cores (--vectorized runs unpinned and says so), firecode grow on a running VM (the framework cannot resize a drive under a live guest), and memory going back: its balloon has no free page reporting, so a guest that freed memory still costs its high-water mark until it stops. vmprocfs.py needs FUSE-T or macFUSE, and with no /proc on the host there is nothing to fall through to.

Once you have an image, the next one is built inside a VM - no docker, no export, no copy-out:

firecode prepare --in-vm --with "dotnet@10 uv"

The blank image is attached to the builder as an unmounted disk and written directly, so the host holds the finished filesystem the moment the VM stops. It is smaller than the docker path (a package set rather than a container image carrying its history), it refuses to install a result whose /sbin/init is missing, and it keeps the image it replaces as .previous.

It is also the only path that works on a host whose DNS is a loopback DoH proxy: docker's bridge forwards to the host's resolver address, which inside a container namespace is the container itself, so nothing resolves. prepare detects that and builds on the host network; --in-vm never meets it, because a guest has its own resolver.

Two things need root, both one-time:

sudo firecode net-setup --count 4          # persistent taps, owned by you
sudo ./scripts/install-privileged.sh       # passwordless jailed runs

The second one never grants the jailer itself: the jailer execs any file named like firecracker as any uid it is given, so a passwordless rule for it is root for anything running as you. It copies firecracker and the jailer somewhere root-owned and grants only a wrapper (scripts/jail-wrapper.sh) that accepts firecode's own arguments - your uid, that firecracker, a root-owned jail base. Re-run it after firecode setup fetches a new firecracker. Skip it and --no-jail needs nothing at all; you still get a real KVM guest, minus the chroot and uid drop around the VMM process.

Without it, a jailed run still works but asks sudo for the jailer in vendor/bin every time, and its jail lives under .jail/ in the checkout - a directory you own. While that sudo runs, anything running as you could swap the jail directory for a link before the jailer, as root, uses it. The installed wrapper does not have that window: its jail base is root-owned all the way down to the run's own root/.

With no controlling terminal - cron, a hook, another agent - sudo cannot prompt. SUDO_ASKPASS=/usr/bin/ksshaskpass makes it ask on the desktop.

Use

firecode claude "add tests for the parser"     # unattended, shuts down when done
firecode claude --timeout 3600 "big refactor"  # give up after an hour
firecode claude                                # interactive, in byobu
firecode opencode "fix the failing build"
firecode shell                                 # poke around by hand
firecode sh                                    # throwaway shell, project mounted read-only (Mac)
firecode sh -c 'GOARCH=386 go test ./...'      # the same, one command, its exit status
firecode run go test ./...                     # on Linux, against your tree as it is now
firecode exec make -j8                         # any command, in the sandbox

run is the door for "just run this on Linux". The first call starts a VM for the project and leaves it up; every call after sends it only the files that changed since the last (gitignored ones never), runs the command where you are standing, and exits with its status. Nothing is copied back and firecode prints nothing of its own. A call takes about a second. firecode down stops the VM. exec copies the whole project and boots for every command; in runs against the copy up made, which your later edits never reach.

A task means unattended. Flags alone mean a session you drive. So firecode claude --resume <id> gives you the REPL with that conversation loaded, and firecode claude --resume <id> "do X" runs it without you. For the unattended case -p and --dangerously-skip-permissions are added unless you gave your own (--no-auto-flags to stop that). Anything after -- goes to the agent untouched.

Results land next to the project:

~/Projects/thing                       # untouched
~/Projects/thing-20260810-231500-4711  # what the agent produced

Nothing is applied for you. Diff it and take what you want.

Sessions

Interactive runs live in a byobu session named after the project, which makes them a singleton: a second firecode claude in the same project joins the running VM instead of starting a rival one.

firecode claude          # session firecode/thing, ctrl-a d to detach
firecode attach          # back into it, including over ssh
firecode list            # sessions and runs

Because the session owns the VM rather than your terminal, closing the terminal no longer leaves one running. --no-tmux opts out.

To get a shell inside a VM that is already running - to try the thing the agent just built, or watch it work - firecode enter. The guest serves a pty per connection, so it does not disturb whatever is on the first one, and leaving does not stop the VM.

firecode enter                    # second shell in the running VM
./impersonate-cs/publish/dash     # run what it built
# then open http://172.16.1.2:8080 in your browser

Three rungs: throwaway, worktree, copy

How much of your project a VM gets, from least to most. The first two are a Mac's (virtio-fs); on Linux everything is the third.

the project what comes back for
firecode sh mounted read-only, with a throwaway layer over it nothing - the VM and its disks are deleted running tests, poking around: a contained shell
a git worktree (--worktree NAME, or any worktree as the project) the worktree mounted read-write, the main checkout read-only, the repository's .git read-write nothing to copy: edits and commits are in the worktree and the repository as they happen agents doing work, the way a host agent would
a folder, --mount-rw (what letibot --vm uses) the directory itself, read-write: a folder of repositories, every one in it nothing to copy: edits, worktrees beside a repository, commits all land as they happen a whole agent session and its subagents working on a set of repositories, everything allowed, nothing else of the host reachable
anything else copied in a sibling <project>-<timestamp> when it stops (down --discard for none) full isolation of a tree you do not want touched

The worktree rung is where agents belong. firecode claude --worktree fix-x in ~/Projects/stroppy-io/stroppy makes ~/Projects/stroppy-io/stroppy-fix-x on branch fix-x, beside the repository and nowhere else, and runs in it. The agent reads the canonical checkout but cannot change it; it commits to its branch with git's own machinery, so git log fix-x shows its work while it is still running. It could also move other branches of that repository - as an agent on the host could - and nothing outside the repository is reachable. --copy gives the old behaviour: a copy, with commits fetched back at the end.

A VM nobody will resume is --ephemeral. Everything a run leaves in state/ is kept by default so the next run can --continue and so a rebuilt toolchain is not built twice; a caller that starts dozens of short-lived VMs a day and never comes back keeps all of it forever, which is how state/ reached 800G and filled a root filesystem. With --ephemeral (or FIRECODE_EPHEMERAL=1 for a caller that cannot pass flags) the session's layer, agent home, working tree and lock are removed when the VM stops - after the work is copied out, never before, because the copy-out is the only copy there is:

firecode claude --ephemeral "try the upgrade and tell me if it builds"
firecode down            # ...and prints how much disk that gave back

A copy-out that fails keeps every file and says where, and firecode extract reads it back out of the src drive. The project's layer goes too - that is the point, and it is why this is a flag and not a default.

The guest root is not a disk, it is a stack, assembled by an initramfs before the guest boots:

layer what it is writable
base image what prepare built, shared by every VM no
imported images docker images added with firecode layer add, one per digest no
project layer the main checkout's, where its toolchains live only from that checkout
workspace layer this directory's own yes

A git worktree gets its own workspace layer and inherits the main checkout's read-only - the same relationship it has to the repository. So the main checkout can be on dotnet 8 and a worktree on dotnet 9, neither disturbing the other, both sharing one base image.

--worktree makes one if it is not there, and runs in it:

firecode claude --worktree parser-rewrite "port the parser"
firecode claude --worktree docs "update the docs"      # at the same time

A worktree's .git is a file pointing back into the main checkout, which is not in the VM, so the copy gets a real .git built from the repository's common directory with git itself setting the branch. History and commits work in there.

The work comes back into the worktree itself, with no timestamped copy beside it - firecode created that worktree, so firecode may write to it. The VM's commits are fetched into your repository and the branch moved onto them; uncommitted edits land in the working tree. Afterwards it is an ordinary worktree:

git -C ../thing-parser-rewrite log --oneline
git merge parser-rewrite
git worktree remove ../thing-parser-rewrite

Your own checkout is never treated this way - it stays untouched and you get the sibling copy.

Nothing is copied per run: a VM adds a sparse layer rather than duplicating six gigabytes of rootfs.

A toolchain you want everywhere belongs in the base image, not installed per workspace:

firecode prepare --with "dotnet@10 java@temurin-21 uv"

mise installs them into /opt/mise, readable by every account in the guest, and the choice is remembered so a later rebuild keeps them. --with "" clears it. --full additionally puts rust, go, zig, clang/llvm and sbcl in the image.

Resuming

Everything a session touched persists per workspace: the conversation, the working tree, and whatever it installed.

firecode claude "start the refactor"
firecode claude --continue "now do the tests too"

firecode state sessions                      # ids you can resume
firecode claude --resume 3f9a1c2e "and the docs"

--continue and --resume carry the tree forward too, not just the conversation - resuming into a pristine checkout would tell the agent it had made changes that are not there. --fresh starts from your tree again, --fresh-root throws away the workspace layer.

A session you started on the host can be moved in:

firecode claude --import-sessions --resume <id> "carry on without me"

Nothing is rewritten in the transcript, because the project has the same path on both sides - which is the main reason it has the same path. Your host transcripts are only read, never modified.

Snapshots

A project's state is three drives - agent home, working tree, workspace layer - and snapshot captures them together.

firecode snapshot toolchain-installed
firecode snapshot ls
firecode snapshot restore toolchain-installed
firecode snapshot rm toolchain-installed

Restoring puts the next run exactly where the snapshot was taken. Sparse copies, so 13G of drives is about 1.4G on disk. Restore refuses while a run holds the project.

This is disk state, not a paused VM. Saving a running VM - memory and all - is what checkpoints do, below.

Reaching things

The host, from the guest. MCP servers exposed over http on localhost:PORT are relayed in and reachable at the same address. Anything else on your loopback - a local model server, say - goes in ~/.config/firecode/host-ports, one per line, or --host-port 18080 for one run. This runs over vsock, not the network, so it works under --no-net too.

MCP servers configured as local stdio commands cannot come along; their binaries are on the host filesystem, which is the thing being kept out. They are dropped, and named when the config drive is built.

The guest, from the host. Your host is the other end of the guest's link, so a dev server it starts is directly reachable. A project keeps the same address across runs - it is picked from the taps that exist by hashing the project path - so a dashboard stays at a URL you can bookmark. firecode prints it either way, and falls back to any free tap when that one is busy:

[firecode] guest is 172.16.1.2 - a server it starts on PORT is at
[firecode]   http://172.16.1.2:PORT

Files, either way, while it runs. Firecracker has no virtio-fs and no 9p, so a host directory cannot be shared into a guest at all. vsock can:

firecode cp vm:~/Projects/thing/dist ./dist
firecode cp ./logo.png vm:~/Projects/thing/assets

Coming out, the archive is written by the guest, and the guest is the thing being contained - so extraction goes through Python's data filter, which refuses .., absolute paths, links pointing outside the destination, device files and setuid bits by specification rather than by whichever tar is installed. --limit caps a guest that never stops sending.

Extra context, read-only:

firecode claude --add-dir ~/Projects "match the API the sibling repo uses"

Mounted at its real path, gitignore-filtered, and cached between runs. Copies: the guest can read them, nothing written there goes back out.

What the guest may print at you

A terminal executes some of what is printed at it, and everything the guest prints is written by the thing being contained. Its output is filtered on the way to your terminal:

  • dropped: OSC 52 (setting your clipboard), DCS/APC/PM/SOS payloads - which on some terminals include "define this key to type the following", outliving the session - ESC c, a full reset that wipes your scrollback, and window operations (CSI ... t): resizing you, and title-report queries some terminals answer by typing the title - which the guest chose - back as input
  • kept: the rest of CSI, so cursor movement and colour still work, and OSC 0/1/2 for the window title, because without those a TUI cannot draw

An unattended run is stricter still: it prints logs, so nothing but text gets through. The console log keeps the unfiltered bytes, so the record is complete. --raw on the console turns the filter off.

What tools the agent has in there

Split by transport, not by which server you like:

your MCP server in a VM
http on the host's localhost relayed over vsock - localhost:9755 in the guest is localhost:9755 out here, same address, no config change
stdio (a local binary) dropped - the binary lives at a host path that does not exist in there
interactively authenticated (claude.ai connectors) absent - the guest cannot open a browser to log in

Every run says which is which, so it is visible rather than folklore:

[firecode]   MCP unavailable in guest (host stdio binaries): codebase-memory-mcp, serenedash
[firecode]   MCP relayed over vsock: oracle-ask, source-grep, oracle-lsp

To get a stdio server into a guest, either install its binary in the image or wrap it in http on the host, where it is relayed like the rest.

A spawned run is different and deliberately so: it is started with an empty MCP config, so it has no tools at all. Why that boundary exists, and what a child keeps regardless, is under Spawning more VMs.

What the agent is told

Three things reach the model, and only these:

  • your host ~/.claude/CLAUDE.md, unchanged
  • the project's own CLAUDE.md, if it has one
  • a firecode section appended to the first: that it has root and should stop asking, that its work leaves through a sibling directory, that installs persist, that stdio MCP servers are absent, that there is no gh and no ssh key

That section also carries what a delegated run keeps getting wrong, written down because instruction is cheaper than supervision:

  • run it early - one or two files, then compile or import or start it. The worst run here wrote eight files over 24 minutes before invoking a compiler once, and every error after that was entangled with the others.
  • load what you deliver, in a new process, from the project as it will be copied out - a long session accumulates state the recipient will not have.
  • no placeholder survives: nobody is coming back to fill it in, because the only one who was going to is the process about to stop.
  • the room exists, and reaching it is firecode-chat, not a tool.

FIRECODE=1 and IS_SANDBOX=1 are in the environment. Commits use the git identity the project reports on the host, with signing forced off - there is no key in the guest and nothing there could answer a passphrase.

opencode gets its credentials and provider config carried in - minus the provider a relay is standing in for, and minus MCP servers whose binaries live on the host filesystem, which it would otherwise sit trying to start.

How it works

Drives are found by filesystem label, not device order:

label mount contents
firecode-src the project's host path your project, writable, copied back out
firecode-cfg /opt/firecode/config read-only: agent binaries and host config
firecode-ctl /opt/firecode/run read-only: this run's parameters and guest scripts
firecode-state /var/lib/firecode per-project agent home, survives the VM
firecode-x* their host paths read-only: whatever --add-dir asked for

The root layers come first, by device, because the initramfs assembles them before there is a udev to ask.

Inside, firecode-mounts.service mounts those, recreates your account with the same uid and home, brings up the network, starts the vsock relays, and layers ~/.claude and ~/.opencode as writable overlays on the read-only config drive. Then firecode-agent.service runs the agent, or - for an interactive run - a pty is served over vsock instead of the serial console.

Images are built and read without root: mkfs.ext4 -d writes one straight from a directory and debugfs rdump reads it back, neither needing a mount. The first guest image is built by exporting a Docker container; every later one by prepare --in-vm, written from inside a VM booted off the previous image.

The claude and opencode binaries are not baked in. They are copied from the host at launch, so the guest runs the version you run.

Networking

Each VM gets its own tap and its own /30, so several run at once without colliding. NAT is via iptables plus explicit FORWARD rules, because Docker sets the FORWARD policy to DROP. A slot is taken only if its lock is free and the tap has no carrier - a VM outliving a killed firecode still holds its device.

--no-net gives a VM with no network at all; vsock still works, so relays and cp and the console are unaffected.

Resource limits

--mem and --vcpu are hard limits - Firecracker will not give the guest more than it was configured with. --cgroups additionally caps the host-side VMM process through the jailer, which is mostly redundant and off by default.

--mem is a ceiling, not a reservation. Guest memory is mapped on demand, so a 4G VM that has used 900M costs the host 900M. And it is given back: every VM has a virtio balloon with free page reporting, so memory the guest frees returns to the host within seconds - measured, a guest that allocated and freed 1.5G went from 1741M resident back to 219M. Without it a VM stayed at its high-water mark until it stopped. Only whole 2M blocks are reported, so a guest pushed near its limit gives back less. FIRECODE_BALLOON=0 turns it off. It does not make overcommit safe: if every VM grows at once, the host's OOM killer still picks one. A GPU passthrough VM under libvirt has its memory locked for DMA, resident from the start, and never reports.

Orchestration

A VM that stays up, for when you will run more than one thing in it - a test suite you are iterating on, a build you do not want to pay for twice:

firecode up                       # boots and waits until it can take commands
firecode in 'cargo test --release'   # output, and the command's own exit status
firecode in 'python3 bench.py'
firecode down                     # stops it, copying the work back out
firecode down --discard           # stops it, and nothing comes back

in returns the command's exit status, so a failing suite and a suite that could not start are different things. Several VMs can be up at once, one per project; --project DIR says which, and asking ambiguously lists them rather than guessing.

A VM that stays up can be held to a gate too. firecode up --verify 'CMD' runs CMD when the VM is brought down - after whatever was done in it, before the guest stops, in the project as it will be delivered - and down says the verdict beside where the work went:

[firecode] running its gate before it stops: make e2e
[firecode] work delivered: /home/you/Projects/thing-20261011-194613-30065
[firecode] VERIFY FAILED (exit 2) - its output is .firecode-verify.log in the delivered work

The verdict is also a file on the run, runs/<id>/verify-status, for whatever placed the VM to read rather than parse. This is what makes a VM driven with up/in/down - an agent on the host using the guest as its hands - as checkable as an unattended run: before it, down rebooted the guest out from under the gate, so a --verify given to up never ran.

Containers inside a guest

The projects that most need isolating are often the ones whose test stack is a compose file, so a guest runs docker:

firecode up --mem 16384 --vcpu 8
firecode in 'docker compose up -d --wait && make e2e'

docker, compose and buildx are in the image, socket-activated: nothing starts at boot, and the first docker command starts the daemon. Your account is in the docker group. Two things make it work, and both are worth knowing when it does not:

  • Every kernel module is there. A guest used to have only the four its root needs, so docker died on its bridge, its netfilter and its conntrack. The whole module tree now comes on a read-only drive shared by every VM (images/modules-<ver>.ext4, built by setup), and modprobe works by name. depmod's indices are made in the guest and kept per project. This is the Mac's kernel, Ubuntu's. On Linux the guest boots firecracker's kernel, which has no loadable modules: whether it has docker's bridge and netfilter built in has not been checked, and if it has not, scripts/build-kernel.sh's config list is the place to add them.
  • Its storage is not on the root. The root is an overlay, and docker's overlay2 cannot mount inside one. /var/lib/docker and /var/lib/containerd are on the workspace layer's own filesystem instead - so pulled and built images survive the VM, per workspace, like anything else it installs.

Size the layer for the stack. Images, volumes and the build cache share the workspace layer, 32G by default. PeerDB's dev stack - 14 services, six images built from the repository - filled the 16G it used to be: 3.3G of images and 8.9G of build cache. docker builder prune -af after the build gets most of that back; for a stack you build often, give the workspace room up front, which applies when the layer is created (--fresh-root makes a new one):

firecode up --layer-size 48G --fresh-root --mem 16384 --vcpu 8

Delegating a job, and staying in the conversation

An unattended run is not a black box. It says what it is doing as it does it, it can be spoken to while it works, and what it hands back is checked by the harness rather than described by the agent.

firecode claude --deliver ~/Projects/thing \
  --verify './run_tests.sh' \
  -- -p 'build the thing, tests and all' --dangerously-skip-permissions

firecode logs -f thing-vm         # what it is doing, as it happens
firecode say thing-vm 'the spec changed - RFC 2812 rather than 1459'

--verify CMD is the part that makes "done" mean something. The harness runs CMD itself after the agent has exited, inside the VM - where the toolchain the agent installed actually is - in the project directory as it will be handed over. Its exit status becomes the run's, its output is delivered as .firecode-verify.log, and the agent is told at the start what the command will be, so it can aim at it.

This exists because of two runs in one evening. One delivered a Lisp system whose .asd named files that were not there, with a test that started a server, slept, stopped it and printed "test completed"; the other delivered a Postgres extension whose README ended a results section with the literal string RESULTS_PLACEHOLDER over an empty file. Both reported success, both took hours, and in both cases the last thing checked was not the thing being handed over. An agent asserting success is a claim about a process that is about to stop, made by the only party who could have checked and did not.

What the gate is not: proof against an agent that wants to fake it. It runs in the same VM, and the agent has passwordless root in there - it can leave a process behind that rewrites the result, or replace the check itself. The harness closes the cheap ways (the verdict is written where only root can reach, markers the agent planted are cleared first, and a gate whose verdict never arrives is a failure, not a pass), but the gate guards against honest mistakes - a test that does not test, a file that is not there - not against an adversary. A gate that has to hold against the agent belongs in a fresh VM booted from the result, which the agent never ran in.

firecode say posts another turn into a run that is already going, so a correction that occurs to you in minute ten does not have to wait for the end and a whole new run. Both agents take it, by different routes: claude reads further turns from stdin, and opencode is attached to a server of its own so the message goes into its session.

firecode watch <vm> waits, then says whether the run is still up and what it has printed. It takes no flags on purpose. Watching means pausing between looks, and an agent left to invent its own pause writes a different command every time - a bare sleep, then a computed deadline, then its own choice of tail length - so whoever is approving that agent's commands is asked again every couple of minutes and can never grant it once. Over MCP vm_watch goes further and does not poll at all: it blocks until the VM exits, until text you named appears, until the run has been quiet too long, or until a timeout.

The gate has to be armed. Writing "I run ./run-tests.sh after you exit" into the prompt arms nothing: the prompt is prose for the agent, --verify is a command for the harness, and neither substitutes for the other. A careful caller did exactly that and got a green run whose gate had never executed, on a script that was not in the delivered tree. Say it in both places.

prompts/ has starting points for both halves of this - a build task with a gate, and one agent supervising another.

The room

Every agent here works alone by construction - one per VM, one per session - which is the isolation working and also its blind spot: two of them can spend an hour on the same wrong assumption without ever finding out.

firecode chat install       # once: a user service, survives sessions and reboots
firecode chat 'text'        # say something
firecode chat --read        # everything so far
firecode chat --inbox       # block until somebody speaks, then print and exit

Inside a VM the same room is a command, firecode-chat, installed into every guest. An unattended run gets no MCP servers by design, so three agents in a row looked for a chat tool, found none, and concluded there was no room - one of them while blocked on something the others could have answered in a sentence.

firecode-chat 'blocked: no postgres in the image and apt cannot resolve'
firecode-chat --ask 'install from source, or stop?'

--ask posts and waits. An unattended agent facing a decision it cannot make otherwise has two moves - guess, or stop and report that it needed a human - and both are worse than asking and waiting a few minutes. If nobody answers it says so and tells the agent to decide and record what it chose.

Two conventions the room needs, learned by getting them wrong:

  • Start listening before you start working, and start again each time your reader returns. A blocking MCP call cannot be a permanent listener - it freezes the caller's turn - so the listener is a background shell running firecode chat --inbox, which exits on each message.
  • Acknowledge before you act. Silence is indistinguishable from absence: an agent here waited three minutes for an answer, concluded nobody was coming, and went and fixed the thing itself.

Checkpoints

Firecracker can save a running VM - guest memory and device state - and map it back later. A cold boot spends most of its time allocating guest memory (~2.4s of a 4G VM's 2.9s; the guest itself boots in half a second). A restore skips all of it and the guest is answering again in about 60ms.

firecode checkpoint     # freeze the VM running now, exactly as it is
firecode up --fast      # bring that back instead of booting
firecode up --refresh   # throw it away and take a new one

What makes this worth having is not the boot time - it is that state a VM took real work to reach becomes reusable. Generate test data, load a database, get a fixture into a state worth keeping, checkpoint it once, and from then on every run starts there:

firecode claude          # "write a generator for representative data, then use it"
firecode checkpoint      # freeze the loaded fixture
# ... the agent wrecks it, as it should ...
firecode down && firecode up --fast    # back to the loaded fixture, ~1.7s

The restore itself is the ~60ms; the rest of the 1.7s is down - a clean guest shutdown and the work copied back out.

A restored VM is transient. It gets the checkpoint's own copies of every drive it writes to, so nothing it does touches the real project, the workspace layer or the agent state - which is exactly why it can be reset over and over, and why the checkpoint never goes stale by being used. The read-only layers are shared as always, since nothing writes to them.

A checkpoint is a build artifact, not a live thing. It is stamped with the base images, the project's content, the machine shape (--mem, --vcpu) and the agent binary, and any of those changing means the next fast start boots normally and takes a new one. What it does not track is a toolchain installed after it was taken - --refresh for that.

This is also the answer to "the agent needs the real database". It does not: give it a generator and a checkpoint of the loaded result. A seed script that runs on the host would be a way for a VM to run code outside itself, which is the one thing this is all for.

Watching something inside a VM from out here

Anything that inspects a running process wants three things, and they cross a VM boundary in three different ways:

how it gets across
a socket to connect to TCP - the VM has an address
files, like perf captures firecode mirror copies them out
/proc it does not travel at all, so mount the guest's

That last one is the trap. /proc is the kernel of the machine you read it on, so a tool running here describes this machine while the process it is reporting on runs in a VM - and it looks perfectly healthy doing it.

eval "$(firecode info --env)"        # FIRECODE_VM_IP, _SOCKET, _RUN ...
firecode mirror --once --out ~/.cache/vm '/tmp/*.perf.data'
scripts/vmprocfs.py "$FIRECODE_VM_SOCKET" 1026 ~/.cache/vm/proc &

firecode info deliberately reports facts rather than any particular tool's settings; mapping them is one line each, in your own shell. For serenedash:

eval "$(firecode info --env)"
export SERENEDB_TARGET=remote SERENEDB_HOST=$FIRECODE_VM_IP SERENEDB_PORT=7891
export SERENEDASH_PERF_DIR=~/.cache/vm/tmp
export SERENEDASH_SYMBOL_PATHS=/path/to/build/bin
serenedash --once

Measured against a SereneDB running in a VM: the SQL panels are live, and the profile panel resolves a capture taken inside the VM against a local build - duckdb::dict_fsst::CompressedStringScanState::ReconstructEntry at 23.7%, columnar work 79.6% of samples. The panels that read /proc describe this machine until they are pointed at the mount.

Symbols need a build with symbols and a matching build-id. A stripped binary profiles perfectly and resolves to nothing, and nothing says so - which is why running your own build inside the VM is the shortest path to a readable profile.

Spawning more VMs

Firecracker exposes no virtualization extensions to its guests, so a firecode VM can never run a firecode VM. It can ask the host to start a sibling, through an MCP server reached over the same vsock relay as everything else:

cp mcp/spawn.example.json spawn.json    # list the projects that may be spawned
firecode spawn-server
firecode claude --orchestrate "farm this out across the sub-projects"

Who may use it. A VM is known by its connection - the relay carrying it runs in the VM's cgroup, so the server reads which run is asking and the guest has nothing to forge. Only a VM started with --orchestrate is let in, and then it can spawn on its own project or on scratch it made, use the vm_* tools on that scratch only (a project's VMs can include your own interactive session), and see, cancel and land only the runs it spawned - never with force. The spawn port is never relayed into a VM any other way, whatever ~/.claude.json or the host-ports file lists.

Everything else on this machine counts as the host, which includes any web page a browser here is showing, so the host must send the token the server keeps in ~/.config/firecode/spawn-token:

claude mcp add --transport http firecode-spawn http://127.0.0.1:9770/mcp \
  --header "Authorization: Bearer $(cat ~/.config/firecode/spawn-token)"

Requests must also name the server by address in Host (no domain, which is what DNS rebinding needs) and carry Content-Type: application/json.

Projects are named keys from the config, never paths from the caller - otherwise an agent could ask for any directory and read it in a VM it controls. An agent that has nowhere of its own to work asks for workspace_new, which makes one inside a scratch directory the operator nominates - before that existed, every agent borrowed the one configured project and built over what the last one left.

Children run with --no-mcp and an empty --mcp-config, so they cannot reach the server and spawn in turn - a child that could would make the concurrency caps meaningless. It is a policy in the spawn server rather than a limitation of the harness, and it is about fan-out, not about voice: a spawned agent still has firecode-chat and can say it is blocked or ask a question. Talking and fanning out are different powers. If you ever relax the flatness, the three conditions are a depth budget decremented per level, a fresh workspace per child, and the parent run recorded on it - the second because two runs sharing one workspace layer corrupt it, which surfaces as a guest whose root has gone read-only.

The tools come in two shapes. spawn, status, output and cancel are for work handed off and collected later. vm_up, vm_in, vm_down, vm_list, vm_checkpoint and vm_reset are for a VM an agent holds and iterates in - bring it up once, get a fixture into it, freeze that, and reset to it between runs instead of rebuilding it. list_projects says what it may touch.

A spawned VM is a sibling on the host rather than a child process of the VM that asked for it - but it does stop when that VM stops. Each run owns a cgroup, a VM started on another's behalf is nested inside its parent's, and tearing a run down takes its descendants with it: asked politely first, so their work still gets copied back, then not. firecode list shows what is running and which VMs are tied to which.

The parent is worked out from the connection - a guest reaches the host through a relay that runs inside that guest's own cgroup - so nothing has to be declared by the guest or believed from it. See ARCHITECTURE.md for the ownership model and the invariants the tests hold to.

Tests

firecode test           # everything, boots VMs, ~10 minutes
firecode test --quick   # host-side only, seconds
firecode test denylist  # one by name

They run --no-jail --no-net, so no privileges are needed; the jailed test skips itself unless the jailer runs without a password. What they pin down, in rough order of how much it would hurt to get wrong: host transcripts are byte-identical after an import; a guest that deletes its whole project leaves the host tree untouched; the denylist refuses a path as --workdir, as a subdirectory, as --add-dir, and as a parent whose copy would carry a sensitive path; gitignored files stay out and git history comes along; the guest's paths, home and uid match the host's; the agent's home survives into the next run; work reaches the result directory and does not leak into the source tree; two concurrent runs take different taps and only one holds the state drive.

firecode keys prints the bytes the guest receives for each keypress, which is the tool for "this key does nothing in the TUI".

Where the disks live

Two directories, both read once at startup and used by every path firecode builds:

variable default what is in it
FIRECODE_STATE <checkout>/state the disks: per-project layers, agent homes, src drives, locks, checkpoints
FIRECODE_RUNS <checkout>/runs one small directory per run: console log, copy-out record, result path

State is the one that grows: a layer is 32G sparse and tens of gigabytes real after a build, an agent home is 3G, and a src drive is 4G. On a host with a small root filesystem, put it somewhere with room:

export FIRECODE_STATE=/build/firecode-state
export FIRECODE_RUNS=/build/firecode-runs   # optional; runs are small

Jails go beside the state ($(dirname $FIRECODE_STATE)/.jail, or FIRECODE_JAIL), because the writable drives are hardlinked into the jail. A jail on another filesystem is refused at boot: a copied drive takes the guest's writes with it when the jail goes.

Both are inherited by every run and by the spawn server, reap-layers.sh and boot-timings.sh, so nothing keeps reading the default behind your back. firecode doctor answers "why is this host out of disk" in three lines: how much state there is, how much room is left on that filesystem, and how many sessions are stopped and still holding it (and of those, how many are ephemeral and reclaimable right now with firecode gc --state).

A full disk kills VMs that are not yours. On 2026-11-13 state/ reached 800G, the root filesystem went to 100%, and three agents' VMs died mid-work with errors naming their own builds. So making a new layer now begins by looking at the free space where state lives: under FIRECODE_MIN_FREE GB (default 50) the ephemeral sessions are reclaimed first, and if that is still not enough the run stops and says so, with the commands that free room. A refusal that costs one run is cheaper than a full disk that takes everyone's.

FIRECODE_MIN_FREE=10 firecode claude ...   # a small disk, deliberately

Housekeeping

firecode list                 # sessions and runs
firecode extract <id>         # pull a run's project back out (with --keep)
firecode gc                   # drop old run drives, keep the last 5
firecode gc --state           # and the state of sessions untouched for 2 days
firecode gc --state --dry-run # what that would remove, with sizes

firecode layer add IMAGE      # a docker image as a read-only layer, by digest
firecode layer ls             # which images this project boots with
firecode --disk DEV:/mnt:rw   # a host disk or snapshot, attached not copied
firecode --vmm libvirt ...    # the other hypervisor: qemu, and PCI devices
firecode --gpu auto ...       # pass the discrete GPU (implies libvirt)
firecode --vectorized ...     # pin to performance cores, and say what cannot
                              # be measured here
firecode --kernel debug       # the traceable kernel: ftrace, kprobes, BTF

firecode state list           # per-project drives
firecode state ls [--json]    # who each session belongs to, what it was for,
                              # what it costs, whether its work is out
firecode state release NAME   # done with this session (the caller's session-end
                              # hook; idempotent, --json, --dry-run)
firecode state reap --owners - --json
                              # release every session whose owner is gone, from
                              # the list of owners that are still alive
firecode state reset          # forget this project's history, tree and layer

firecode gc --state --budget 150G   # keep the state under a ceiling: worst
                                    # first, never unextracted work, and it
                                    # says when it cannot get there

firecode pool take --project P --json   # is there a warm VM for this project?
firecode pool return NAME --json        # give it back (work out, reset, caches
                                        # kept) - or --sleep to stop it now
firecode pool sleep --idle 300 --json   # a reaper's pass: stop idle members,
                                        # keep the pool under its caps
firecode pool status [--json]           # what is in the pool, and in what state

firecode net host-guard --print  # the rule that keeps a guest off this host's
                                 # own services; the LAN and internet stay open

scripts/canary-roundtrip.sh      # boot, commit, extract, verify, release, and
                                 # --pool: back to the pool: the check to run
                                 # after any storage change

Per-run drives are deleted when the VM exits unless you pass --keep. Console logs stay. Snapshots are never touched by gc, and neither is state/ - except by gc --state, which is the pass that exists because it has to be somebody's job: a project's state outlives the runs that made it (that is what --continue and a once-paid toolchain are), so it only ever grows. It touches a session only when no run of it is in progress, and only when nothing has touched it for the age - an ephemeral session's state, which nobody will resume, goes at any age.

Every session carries a manifest (state/<slug>.json) saying whose it is, what it was for, and whether its work was copied out. Every copy-out makes a bundle of the tree's refs and verifies that the bundle contains the commit the guest was on, so "the work is out" is a recorded fact with a tip rather than a log line somebody read. Nothing whose manifest says its work is not out is ever deleted by gc or by state release - --force says so in words, and firecode extract <run> --bundle is how the work comes out of a session whose copy-out failed. Sessions from before manifests read unknown, and the pass says how many of those it removed blind.

A reviewer's VM (or any session started with --reuse) can go back to its project's warm pool instead of being deleted: pool return resets the worktree, keeps the caches (target, .sccache, node_modules, .venv), clears the agent's conversation and shell history, and marks it available; pool take hands it to the next session of that project. It refuses to pool a VM whose work is not out, or one that still has a process running in it - those would wake up in the next user's machine. A member sleeps as a clean shutdown with its disks kept; a memory snapshot is --memory, off by default (it costs 4G of disk for a 4G guest, and carries processes across users).

A reusable session's VM has usually stopped already by the time anyone gives it back - exec runs one command and shuts its VM down. So pool return returns its disks: they are kept, the member is asleep, and the reset no guest was there to run is owed to the next boot, which runs it in the guest before the new user's command and fails the run if it cannot.

--vmm libvirt talks to qemu:///session - qemu runs as you, reads the images under your home, and uses the same taps. --gpu switches to qemu:///system, which a passed-through device needs; that daemon runs qemu as libvirt-qemu, so it has to be able to traverse your home (firecode doctor checks). LIBVIRT_DEFAULT_URI overrides either.

Limits and caveats

  • Your host credentials go into the VM unless you use --auth-relay, which authenticates through this host and leaves the VM holding none. The isolation is of the host filesystem; without the relay it is not of your API keys.
  • The result directory looks like a full copy of the project, and the files that came back unchanged are copies of the ones on disk: cloned where the filesystem supports it (cp --reflink=auto, so btrfs and xfs share the blocks and it costs nothing) and a real copy on ext4. Diff it, read it, edit it in place, delete it freely - a sed -i in the result cannot reach the project. That used to be a hardlink, which meant it could.
  • Two runs at once on one project: the second gets throwaway copies of the state drive and the workspace layer, so what it installs is not kept and its session is not resumable. It says so at the time. (Until recently the layer was shared read-write between them, which corrupted it - the symptom was a guest whose root went read-only and a run that died saying "mount point is not a directory".)
  • An OAuth refresh inside a VM rotates the token and that copy is discarded, so the host is left holding a spent one and needs a re-auth. --auth-relay is the way out: the model is reached through this host and the VM holds no credential for that provider at all.
  • x86_64 Linux, or Apple silicon macOS 14+ (see On a Mac).