Fork() for AI agent microVMs. Spawn 100 children in ~100ms from a warm parent; BRANCH a live VM in ~150ms. KVM-isolated, snapshot CoW.
Fork() for AI agent microVMs. Spawn 100 children in ~100ms from a warm parent; BRANCH a live VM in ~150ms. KVM-isolated, snapshot CoW.
A microVM sandbox runtime for AI agent fan-out. Children fork from a warmed parent snapshot, inheriting its address space copy-on-write instead of cold-booting their own kernel.
forkd is built on Firecracker. The parent VM boots once, imports
your runtime (Python + your dependencies, a JIT-warmed JVM, an
already-loaded ML model) and is paused to disk. Each child is a
separate Firecracker process that mmaps the parent's memory image
with MAP_PRIVATE; the kernel implements copy-on-write at the page
level, so children share the parent's resident memory until they
diverge.
The result is two properties at once: per-child KVM isolation, and a
spawn cost that's closer to fork(2) than to a cold-boot VM.
forkd also supports BRANCH: pause a running sandbox, snapshot its in-flight state, and resume — all in ~150 ms — so an agent can fork mid-thought, not only at warm-up. v0.3.4 fixed a slow-path regression where repeated BRANCHes on the same parent ballooned from 150 ms to 2.7 s (#146); the chain now stays flat (17.6× faster on the 6th consecutive BRANCH).
v0.4 live BRANCH collapses the source-pause window from ~200 ms
(Diff) to 56 ms p50 / 64 ms p90 on a 1.5 GiB source — measured
on a real BRANCH workload, bench/live-fork-pause-window/RESULTS-v0.4.md.
3.6× faster pause vs v0.3 Diff at p50, and the gap widens on
slower storage because Live's pause is disk-independent (memory
copy runs after resume, not during). With wait: false the caller
returns in ~70 ms while the background copy completes asynchronously
— a 200× RT improvement for fire-and-forget BRANCH from agent
code. Pass --live / --no-wait on the CLI, mode: "live" /
wait: false on REST, or the same on the Python / TypeScript / MCP
SDKs.
from forkd import Controller
c = Controller()
# Source must boot with live_fork=True (memfd-backed RAM, the prereq
# for UFFD_WP to see writes from the running parent).
parent = c.spawn_sandboxes("pyagent", n=1, live_fork=True)[0]
# ... drive parent ... then BRANCH live + fire-and-forget:
branch = c.branch_sandbox(parent["id"], mode="live", wait=False)
# Returns after ~10 ms with status="writing"; poll list_snapshots
# until status="ready" for the background copy to finish.# CLI: spawn live-fork-capable children locally, then live-BRANCH the
# daemon-tracked one. The two paths don't compose yet — daemon-side
# spawn from the CLI is the next gap (see issue #209 for status).
sudo -E forkd fork --tag pyagent -n 1 --per-child-netns --live-fork
sudo -E forkd snapshot --from-sandbox <sb-id> --live --no-waitRequires Linux ≥ 5.7, vm.unprivileged_userfaultfd=1 (or
CAP_SYS_PTRACE), and the vendored Firecracker fork from
deeplethe/firecracker:forkd-v0.4-mem-backend-shared-v1.12
— forkd doctor probes both. Full design:
DESIGN-v0.4.md. Empirical PoC data:
experiments/v0.4-*-poc/. Tracking issue
#101.
Once an agent starts caching pip install numpy, pip install pandas,
pip install scikit-learn as separate snapshots, you want them
stacked — not three copies of the same 1.5 GiB base. v0.5 ships
diff-snapshot chains: each layer records a parent_tag +
content-hash edge to the layer below; the daemon walks the chain at
spawn time and assembles the memory image in one pass.
…Phase 5 bench numbers (bench/chain-spawn/RESULTS-v0.5.md)
on a 512 MiB base, ext4, i7-12700:
| chain head | depth | spawn p50 | per-link tax |
|---|---|---|---|
| base (flat) | 0 | 59 ms | — |
+numpy |
1 | 751 ms | +692 ms |
+pandas |
2 | 1 222 ms | +471 ms |
+sklearn |
3 | 1 668 ms | +446 ms |
| flat-equivalent (3 pkgs, one diff) | 1 | 746 ms | — |
Per-link tax tracks SHA-256 of the base (~460 ms for 512 MiB at 1.1 GiB/s on this CPU) — the mmap-once-then-incremental verify optimization is queued as v0.6. Correctness: 90/90 (100%) probe passes across L1/L2/L3 plus the flat-equivalent — the design's vmstate-drift question is empirically closed.
Tracking issue
#216 lists every
phase + PR. Design doc:
DESIGN-v0.5-diff-snapshot-chains.md.
A 24-second walkthrough of the LangGraph branch-and-fan-out demo — source agent runs a ReAct loop, gets BRANCHed mid-thought, three grandchildren each receive a different steering hint, all three produce divergent itineraries while inheriting the same prior reasoning state.
Headline divergence: the source (no hint) picks Nishiki Market for Day 1; all three hinted children independently substitute Arashiyama Bamboo Grove. The cost-focused child also adds "may be pricey" annotations the others don't. The model wasn't told to swap places — each hint perturbed the next LLM call, the rest of the prior reasoning came along unchanged.
Full mechanism + numbers + raw transcripts in
recipes/langgraph-react/ and
recipes/langgraph-react/DEMO.md.
For the "but couldn't you just call the LLM 3 times in parallel?"
objection, see recipes/coding-agent-fork/ —
a 50 MiB binary blob travels byte-identically across all 4 sandboxes
through a single BRANCH. Three grandchildren each apply a different
fix to a buggy Python package; their __pycache__/ and edits stay
isolated, but the 50 MiB inheritance is shared. Bytes can't fit in
a prompt. 3.3 s pause for the BRANCH operation.
runc regression.apt install, outbound HTTPS. Unlike function-level snapshot runtimes
that trade single-vCPU + serial-I/O for raw spawn speed, forkd
children can run real Python servers, model inference, or any
workload that needs a full kernel./dev/urandom re-seeded
by vmgenid (Linux 5.20+).import numpy / import torch cost across the entire
cohort./metrics, append-only JSON audit log, systemd unit.Same Linux host (Ubuntu 24.04, Linux 6.14, 20 vCPU, 30 GiB, KVM).
Workload: spawn 100 sandboxes that each run import numpy; numpy.zeros(5).tolist().
| Backend | Wall-clock at N=100 | Memory delta per sandbox | Notes |
|---|---|---|---|
| forkd | 101 ms | 0.12 MiB | fork-from-warm via snapshot CoW |
| CubeSandbox¹ | 1.06 s | 5 MiB | RustVMM microVM, cold-boot (pool fast path) |
| BoxLite² | 113.2 s | — | KVM microVM, cold-boot OCI rootfs |
| OpenSandbox³ | 122.0 s | — | Docker runtime via abstraction layer |
| Firecracker cold-boot | 759 ms | 84 MiB | raw VM boot, no orchestration |
| gVisor (runsc) | 288.6 s | — | userspace kernel container |
| Docker (runc) | 335.3 s | 4 MiB | standard container runtime |
¹ CubeSandbox: 1.06 s wall-clock is the fast-path N=100 figure on
this host (1056 ± 14 ms over five runs, 100 % success every run),
measured with a bench script that pre-warms Python's
ThreadPoolExecutor to keep client-side lazy-init out of the
timing. An earlier slow-path measurement on the same host returned
20.3 s with 77/100 success — that template had a 2 GiB
writable-layer size that didn't match the default 1 GiB pool, so
every sandbox went through a live mkfs.ext4 + reflink-copy; after
the upstream maintainer at
#235
clarified the distinction, we added 2Gi to
pool_default_format_size_list and re-ran. The host runs cube
v0.2.0, which carries a ~50 ms latency regression that
PR #234
fixes in v0.2.1; the value above is the v0.2.0 baseline. Cube
advertises <60 ms single-instance cold-start on a 96 vCPU
host; we did not retest that shape. See
bench/CUBESANDBOX.md for the full
methodology, both rows, and the cmdTimeout race we filed two PRs
upstream against
(#236 /
#237).
² BoxLite is optimised for one long-lived stateful Box per workload,
not 100 concurrent fresh microVMs. The cold fan-out is included for
direct comparability. See bench/BOXLITE.md.
³ OpenSandbox is an abstraction layer over Docker / K8s / gVisor /
Kata / Firecracker; the number is for its default Docker runtime.
See bench/OPENSANDBOX.md.
Reproduce: bench/bench-spawn-100.sh then bench/generate_charts.py.
For one sandbox doing the same numpy expression two ways:
| Call | Time | What it does |
|---|---|---|
sandbox.eval("numpy.zeros(5).tolist()") |
1 ms | Reuses the warmed Python in PID 1 |
sandbox.commands.run("python3 -c '...'") |
96 ms | Cold subprocess re-imports numpy |
…See DESIGN.md for the full design and the open
problems the architecture leaves on the table.
The sandbox-runtime space has a wide spread of designs. The table below summarises positioning of forkd against the most-cited open-source projects. Numbers in quotes are as advertised by the upstream project unless they match a row in our benchmark chart above. forkd does not measure other projects on workloads they were not designed for.
| Project | Primitive | Cold-start (N=100) | Fork-from-warm | Quotas | Auth / TLS | License |
|---|---|---|---|---|---|---|
| forkd | Firecracker + snapshot CoW | 101 ms | ✓ | cgroup memory.max |
bearer + rustls | Apache 2.0 |
| [CubeSandbox][cs] | RustVMM + KVM microVM | 1.06 s¹ | "coming soon" | <5 MiB / instance | not in OSS | Apache 2.0 |
| [Daytona][dy] | OCI workspace | <90 ms² | ✗ | per workspace | API keys (platform) | AGPL-3.0 |
| [OpenSandbox][os] | Docker / K8s + gVisor / Kata / FC | 122 s | ✗ | via runtime | gateway (k8s) | Apache 2.0 |
| [E2B][e2b] | Firecracker (in [infra][e2b-infra]) | not in OSS | ✗ | platform | API keys (cloud) | Apache 2.0 |
| [BoxLite][bl] | KVM / Hypervisor.framework + OCI | 113 s | ✗ stateful Box | KVM + seccomp | egress policy only | Apache 2.0 |
| Modal | proprietary snapshot fork | not public | ✓ | ✓ | ✓ | proprietary |
| Firecracker raw | microVM only | 759 ms | manual | n/a | n/a | Apache 2.0 |
| Docker (runc) | OCI container | 335 s | ✗ | cgroups | n/a | Apache 2.0 |
| gVisor (runsc) | userspace k |
No open issues yet, or sync has not completed.