Fork a running VM: how live forks work
A fork copies a running VM, memory included, so its processes carry on in both copies. How copy-on-write forks work, why each needs fresh randomness, fork vs snapshot.
3 min read
git branch changed how people write code because trying something stopped being expensive. A live fork does the same for a whole machine: a running VM, its processes, its memory and its disk, copied so two versions carry on from one moment.
What a fork is
A fork is a copy-on-write copy of a sandbox, memory and disk included. Processes that were running in the parent are running in the child, at the same point. The dev server is still up. The database still has the rows you seeded. The agent's shell still has its history.
zode fork demo demo-try-2 --branch try-2demo-try-2 is a copy of demo, running in 19.8sThe child is a new sandbox with its own id and name. After the fork, the two are independent: deleting the parent doesn't touch the child.
Why fork instead of starting fresh
Getting a repository to the point where its tests run is often the slowest part of a task: clone, install dependencies, build, start Postgres, run migrations, seed data. A fork pays that cost once and shares it.
- Parallel attempts. Hand the same problem to two agents, or one agent with two strategies, from identical state. Keep the winner.
- Risky steps. Fork before a migration or a dependency upgrade. If it goes wrong, the original is untouched.
- Debugging. Fork a machine that is in a broken state, then poke at the copy without losing the evidence.
How it works
A running parent is paused for a moment while its memory is saved and its disk is frozen at the same instant, then it carries on. The child's disk starts as a copy-on-write clone of that frozen disk, so nothing is copied until one side writes. Its memory is restored from the saved image, and it comes back running.
On Zode that takes about 20 seconds today. Sub-second forks are on the way, and we will only claim them once they ship.
The part people miss: two copies, one identity
A byte-for-byte copy of a running machine is also a copy of everything that was meant to be unique. Two forks would share the same random number generator state, the same hostname, the same MAC and IP address, and a clock frozen at the moment of the fork. That breaks things in quiet ways: two forks minting the same "random" token, or two machines answering to one address.
So before a Zode fork runs on, the child gets:
- fresh entropy for its random number generator,
- the current time,
- a new hostname, MAC address and IP address.
Programs that care can watch /run/zode/events for a forked event and refresh anything else they cache, such as a session id.
Fork or snapshot?
They answer different questions.
| Fork | Snapshot and restore | |
|---|---|---|
| What you get | A new running sandbox | A saved point in the same sandbox |
| Includes | Disk and memory | Disk and memory |
| Use it to | Try several things in parallel | Roll back after something goes wrong |
| SDK | sbx.fork() | sbx.snapshot(), sbx.restore() |
In code, a snapshot is an undo button around a risky step:
const snap = await sbx.snapshot("before-migration");
await sbx.exec("npm run migrate");
// Not happy? Memory and disk go back to the saved point.
await sbx.restore(snap);Limits worth knowing
- A fork counts as a create: it uses a running slot on your plan and counts against the create rate limit.
- A fork runs on its parent's host. If that host has no free memory, the fork is refused with
node_fulland you can retry shortly. - A fork is billed like any sandbox: compute while it runs, and storage on its full disk size after the first 48 hours.
The reference is on the snapshots and fork docs. If you are forking to run coding agents side by side, Run Claude Code in a cloud VM shows the whole loop.
Try it: install the CLI, or start free in the console.
curl -fsSL https://zode.dev/install | sh