NewInfinite storage: a box whose storage grows as you write.Infinite storage is here.Read the post

BlogHudson Griffith

How we fork a running VM, memory and all

We started a Python process in a Prized sandbox and had it take a random step every 50 ms, then forked the sandbox into 7 copies. 2.9 seconds later, 8 machines were running that process with the same PID and the same memory. Each picked up the walk where the parent left off.

prized sandbox fork $ID --count 7

10 seconds after the fork, at step 514 of the walk, we checked the parent and its 7 copies:

The parent and its 7 copies, 10 seconds after the fork
MachinePIDSHA-256 of 256 MiB in memoryrandom walkos.urandom walkboot_id
box-56c0, the parent14549c1a5e42d53e9923412129afa70
box-fdc014549c1a5e42d53e992340b8ae044f
box-01f814549c1a5e42d53e99234-10cda98bba
box-67a914549c1a5e42d53e992342c0ca0bec
box-fffd14549c1a5e42d53e9923412df96aef4
box-3aa514549c1a5e42d53e992348a9e35a69
box-687c14549c1a5e42d53e9923416ef87eaaa
box-82f614549c1a5e42d53e99234-61579466e

Every machine has its own hostname and boot_id. All eight run process 1454 and hold the same 256 MiB of random bytes in memory. The walks that use Python’s random module are all in the same place, while the os.urandom walks have split (more on that below).

Fork is the feature we’d keep if we could only keep one. An agent spends ten minutes cloning a repo, installing dependencies and warming a build cache, then wants to try seven fixes at once. Without fork that’s seven more rounds of setup. With it, setup happens once and every copy starts with the dev server already running.

How long it takes

On November 25, 2026 we forked 2 vCPU, 4 GB sandboxes on the public service using the SDK from a machine in the same region. We timed each fork from the call until every copy had answered a command.

A fork, by how many copies it makes
1 copy3 copies7 copies
A fork, by how many copies it makes, seconds until every copy answers, lower is better1.321.392.68

Forks of an idle 2 vCPU, 4 GB sandbox on the public service on November 25, 2026, through the SDK from a machine in the same region. Each value is the median of three forks, timed from the fork call until every copy had answered a command. Every copy held the marker the parent had written to memory.

Three copies took as long as one, and seven about twice as long. Fork time also depends on how much memory the parent has used.

A fork into one copy, by the memory the parent has used
0.3 GB1.3 GB2.8 GB
A fork into one copy, by the memory the parent has used, seconds until the copy answers, lower is better1.321.813.86

Forks into one copy of a 2 vCPU, 4 GB sandbox that was idle, or had written 1 GB or 2.5 GB to memory, on November 25, 2026. The parent had 0.3, 1.3 and 2.8 GB in use. Each value is the median of three forks, from the fork call until the copy had answered a command.

The parent stops while we copy it. During the fork, a command we sent the parent took about a second (1,020 ms) if it was idle or had written 1 GB, and 2 to 3.5 seconds after it had written 2.5 GB, up from 11 ms before the fork.

We also timed the steps around a fork that day:

How long each step took
StepMedianRuns
Create, until the first command answers157 ms100
Pause138 ms40
Resume, until a command answers124 ms40
Fork into one copy, until a command answers in it1,335 ms10

Copying the memory

A sandbox is a Firecracker microVM on a host with local NVMe. To fork a running one, the host does four things in order.

  1. It asks an agent in the guest to sync and freeze the filesystem, so the disk is consistent.
  2. It pauses the VM and takes a snapshot of its memory.
  3. It copies the disk as an XFS reflink, which shares every block until something writes to it.
  4. It resumes the VM and thaws the filesystem.

The parent only stops for the snapshot and the disk copy. The snapshot writes out the pages the parent has used, which is why a parent that has touched 2.5 GB stops for longer than an idle one.

A copy doesn’t read in the snapshot before it starts. We register its memory with userfaultfd, and a small page server beside each copy loads pages from the snapshot file into huge pages the first time the copy touches them (Firecracker’s notes on it). The copy starts before most of its memory is loaded and holds only the pages it’s read or written. The disk works the same way one layer down: the reflink costs nothing until a copy writes.

Giving each copy its own identity

Copying the memory turned out to be the easy part. A restored copy wakes up believing it’s the parent. It has the parent’s IP and MAC address, hostname, machine-id and SSH host key. It holds the parent’s token for our command API, its kernel random state and its open TCP connections. Left alone, it would answer as the parent.

A copy’s new identity includes 64 bytes of fresh entropy. Before the copy runs a single instruction, the host writes that identity to a small block device and gives the copy its own tap device (network_overrides on snapshot load). A firewall rule on the host drops anything from that tap that doesn’t come from the copy’s new address.

During a fork, an agent in the guest reads the block device every 2 ms. It uses O_DIRECT because the page cache would keep showing it the parent’s version. When it sees a new identity, it reseeds the kernel’s random number generator, re-addresses eth0 and sets a new boot_id. It hands the new token to our command daemon without restarting it, since a restart would cut off every command in flight. Then it closes TCP connections to other machines and sets the hostname. Loopback connections survive, so your app keeps talking to its local Postgres.

The host trusts none of this until the copy proves it. The new token has to get a 200 back with that identity’s nonce, and the parent’s token has to get a 401. Only then does the host thaw the copy’s filesystem, set its clock and publish it.

It used to stall. Every proof came in a second late, and tcpdump showed why. The host’s first ARP for the copy’s new address went out before the guest had taken it, and Linux waits 1 s before asking again. Probing every 20 ms on that one tap fixed it.

Creates of the common shapes are forks too

Plain creates run the same code. For the common shapes, each host boots a template VM with a made-up identity, snapshots it right after first boot, and keeps a few copies restored and paused. A create claims one, writes its identity, resumes it and runs the same handshake. Most creates don’t boot a VM. That’s why a create in our runs answered its first command in 157 ms.

What a fork doesn’t copy

Fresh randomness inside your processes. We reseed the kernel’s generator in every copy, but a process that already seeded its own generator carries that state into all of them. Our process ran two walks side by side, one on Python’s random module and one on os.urandom.

One process, two random walks, forked into 7 copies

A Python process steps two random walks every 50 milliseconds, one drawn from its random module and one from os.urandom, and its sandbox is forked into 7 copies. On the random module, the parent and all 7 copies stay on exactly the same path after the fork, and leave it only when the copies reseed, about 16 seconds later. On os.urandom, the 8 walks split at the fork.

All 8 random walks stayed on one path until we reseeded the copies, 16 seconds later. The os.urandom walks split at the fork. Reseed or restart anything that makes keys, tokens or IDs after a fork. Firecracker’s notes on clones cover the same problem.

The exact time. A copy starts with the time in the snapshot, so if the sandbox sat paused, the copy would wake up that far behind. If the copy’s clock is more than a second behind, the host sets it to match its own before handing the copy over.

Room on other machines. Copies start on the parent’s host. One request takes up to 256 copies, as long as they fit there. Hosts are shared, so fewer copies of a big sandbox fit on a busy one. A request that won’t fit makes no copies and tells you how many would fit (Fork). If even one more copy won’t fit, the sandbox can’t fork at all. We don’t support forking onto another host yet.

Paused sandboxes fork too

A paused sandbox keeps its memory and disk. Fork it later and the parent stays paused while each copy starts running from that point. Set a machine up once, pause it, and fork a copy per job (guide). Two things can prevent the fork: the sandbox was resized while paused, or a move to another machine left its memory behind. Either way the error says so, and you can fork again once the sandbox has run (Fork).

Try it

ID=$(prized sandbox create --vcpu 2 --memory 2)
prized sandbox exec $ID --timeout 10m -- "git clone --depth 1 https://github.com/expressjs/express && cd express && npm install"
prized sandbox fork $ID --count 3

The fork guide runs a test suite on three Node versions this way. If you fork something strange, tell us how it went at .