2026-11-23
How Flashbox checkpoints every command
Every command an agent runs in Flashbox ends in a checkpoint: the sandbox's state right after it, which you can roll back to or fork into new sandboxes. On our Linux test host a thin command takes {{command_p50}} ms at the median including its checkpoint, and rolling back to any earlier command takes 142 ms. This post explains how, and what we measured before choosing each part.
What has to be saved
A Flashbox sandbox is a small Linux machine: a kernel compiled to WebAssembly, programs on an emulated CPU, and one disk that holds everything the agent can write (/workspace, /tmp and the home directory; the rest of the system is read-only). Its full state is that disk plus the machine's memory.
Saving the memory after every command was our first idea. We measured it on a 256 MiB machine running a typical agent command list: curl, grep, sed, git, short Python and Node scripts.
| Approach | New data per checkpoint (zstd) |
|---|---|
| Whole memory snapshot | 3 to 17 MiB |
| 64 KiB chunks not seen before | 1.2 to 2.4 MiB |
| 4 KiB pages not seen before | 0.6 to 1.8 MiB |
| XOR against the previous checkpoint's pages | worse than plain pages (27 MiB against 16 MiB over 12 commands) |
Even after deduplication, a trivial ls rewrites about a thousand pages of kernel memory, and the changed pages are genuinely new content, so delta encoding does not help. Keeping 1,000 checkpoints of a sandbox that way would cost over a gigabyte.
Most of the time, the files are the state
The memory matters only when something is still running. If a command finishes and leaves nothing behind, a fresh machine with the same disk is indistinguishable from the old one: same files, no processes. So Flashbox keeps two kinds of checkpoint:
- Files, after every command: the disk alone. The wrapper that runs each command calls
syncinside the guest, then the host copies the disk image with a reflink (XFS on Linux, APFS on a Mac). A reflink copy shares every block with the original and costs only the blocks the next command changes. It takes a few milliseconds and is ready before the command's response is sent. - Memory, only while a process runs in the background: the kernel parks every task, the host copies the disk at that instant, and the memory is split into 64 KiB chunks stored by content, so only chunks the previous checkpoint did not have are written. That is about 1958 KiB a time on our test host, written just after the response; the sandbox's next call waits for it.
The command wrapper decides which kind is needed. After each command it counts the sandbox user's processes outside its own session, so a server started three commands ago still counts.
Restoring in milliseconds
Rolling back is the other half. Booting a machine takes 300 to 500 ms, too slow for an agent that wants to undo something. Flashbox keeps warm machines waiting, each with a blank disk already mounted. To restore a files checkpoint, it unmounts that disk, replaces the disk file's contents in place with a reflink copy of the checkpoint (the file keeps its inode, so the machine reads the new blocks), drops the kernel's cached blocks and mounts it again. A new sandbox skips even that: its disk is already mounted, so it is ready in about 26 ms.
Memory checkpoints restore by rebuilding the snapshot from its chunks and resuming the machine, with background processes still running. That takes about half a second on our test host.
Keeping it fair
Two details keep the per-command bill honest:
- The CPU budget is a watchdog, not a limit. Each command runs in its own session with a watchdog that stops it once the guest has used its CPU budget. We first used
ulimit -t, but a limit is inherited: a server the command started in the background would have been killed after a few CPU-seconds. - Background CPU is metered between commands. The wrapper reads the guest's CPU counter before and after each command; anything used in between is background CPU, billed per CPU-minute.
What it costs
On our test host a thin command takes {{command_p50}} ms at the median, including its files checkpoint. A command with a server running in the background takes longer, because the next call waits for the memory checkpoint. Files checkpoints are kept for 7 days and the newest 20 memory checkpoints per sandbox keep their memory. Idle sandboxes cost nothing, and you pay per command.
We measured every number here with the benchmark and test suite in our repository, on a Hetzner cx33 server (4 shared vCPU, AMD EPYC Rome at 2.0 GHz, XFS), on 2026-11-23.