Once a parent snapshot exists, these commands control the sandbox lifecycle — from forking hundreds of children in parallel, to inspecting live sandboxes, to diagnosing the host, to benchmarking real latency on your hardware.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/deeplethe/forkd/llms.txt
Use this file to discover all available pages before exploring further.
forkd fork
Fork N children from a tagged snapshot in parallel. Each child is a separate Firecracker process that mmaps the parent’s memory.bin with MAP_PRIVATE; the kernel implements copy-on-write at the page level so children share the parent’s resident memory until they diverge.
After all restores fire, the command waits --settle-secs seconds, counts alive children, shuts them down, and removes the work directory (unless --keep-workdir is set).
Snapshot tag to fork from. The snapshot must exist at
$XDG_DATA_HOME/forkd/snapshots/<tag>/vmstate.Number of children to fork.
Seconds to let children run before reporting their alive count and shutting down.
Spawn each child inside its own
forkd-child-<i> network namespace. Required for fanout greater than 1 when all children share the same guest IP (10.42.0.2). Provision namespaces first with sudo scripts/netns-setup.sh N. Requires root or CAP_SYS_ADMIN.Optional cgroup v2
memory.max limit per child in MiB. Children exceeding this are OOM-killed by the kernel. Requires root or a delegated cgroup (/sys/fs/cgroup/cgroup.controllers must be present). See crates/forkd-vmm/src/cgroup.rs for implementation details.Back each child’s RAM with a memfd shared region (
MFD_SHARED) instead of a private file copy. Required if you later want to take a v0.4 live BRANCH off this child — mode: "live" arms UFFD_WP on the memfd, which only works on shmem-backed VMAs. Requires Linux ≥ 5.7, the vendored Firecracker fork, and vm.unprivileged_userfaultfd=1. No cost at spawn time beyond the backend swap; cost shows up on the first live BRANCH. forkd doctor probes both prerequisites.Back the memfd with 2 MiB hugepages (
MFD_HUGETLB | MFD_HUGE_2MB). Only meaningful with --live-fork. Reduces TLB pressure during spawn-many and live BRANCH bulk-copy. Requires hugepages to be reserved on the host (echo N > /proc/sys/vm/nr_hugepages). forkd doctor checks availability. Falls back to normal pages with a warning if the pool is exhausted. Requires --live-fork.Keep
/tmp/forkd-fork-<tag>/ after shutdown (default: removed). Contains child console logs and Firecracker API sockets — useful for post-mortem inspection.forkd run
One-shot sandbox: build rootfs from a Docker image (if not cached), take a one-off snapshot, fork one child, exec the command via the guest agent, print stdout/stderr, and shut down. The exit code of the command is propagated as the process exit code.
Equivalent to: build rootfs → snapshot → fork 1 → exec command → shutdown. Use for ad-hoc “give me a quick isolated sandbox” invocations; use forkd fork for high-throughput fan-out.
Docker image to run (e.g.
python:3.12-slim, ubuntu:24.04).Extra apt packages to bake into the rootfs. Repeatable.
Rootfs cache directory. Re-running with the same image skips the Docker → ext4 step. Also read from
FORKD_RUN_CACHE.Kernel image path. Also read from
FORKD_KERNEL.Host tap device. Also read from
FORKD_TAP.Command and arguments to execute inside the sandbox, passed after
--.forkd parent build
Convert a Docker image into a writable ext4 rootfs image with /forkd-init.sh and /forkd-agent.py preinstalled. This is the first step of the manual snapshot pipeline. Calls scripts/build-rootfs.sh internally (must be on $FORKD_SCRIPTS_DIR or discoverable by walking up from the binary).
Subcommand: forkd parent build <image> [flags]
Docker image reference (positional argument). Examples:
python:3.12-slim, ubuntu:24.04.Output
.ext4 file path. Default: ./<image-slug>.ext4 in the current directory.Image size in MiB.
Extra apt packages to install on top of the base image. Repeatable.
forkd ls
List all live sandboxes tracked by the daemon by calling GET /v1/sandboxes. Prints a table of sandbox IDs, statuses, tags, PIDs, and network addresses. Equivalent to querying the REST API directly.
Controller daemon base URL. Also read from
FORKD_URL.Bearer token for the controller daemon. Also read from
FORKD_TOKEN.forkd kill
Kill one or more live sandboxes via DELETE /v1/sandboxes/:id. Supports killing by explicit ID list, by snapshot tag, or all sandboxes at once.
Sandbox IDs to kill (positional, variadic). Ignored when
--all or --tag is set.Kill every live sandbox the daemon knows about. Mutually exclusive with
--tag.Kill every sandbox forked from this snapshot tag. Mutually exclusive with
--all.Controller daemon base URL. Also read from
FORKD_URL.Bearer token. Also read from
FORKD_TOKEN.forkd cleanup
Remove orphaned /tmp/forkd-{fork,parent,unpack,pull}-* work directories and temp files left behind by forkd runs that crashed or were killed before they could clean up. Dry-run by default — lists candidates without deleting. Pass --yes to actually delete.
Sweeps the following prefixes under /tmp/:
forkd-fork-*— child work directories fromforkd forkforkd-parent-*— parent work directories fromforkd snapshotforkd-unpack-*— scratch directories fromforkd unpackforkd-pull-*— temp pack files fromforkd pull
/proc/*/fd/ symlink scanning, not lsof).
Actually delete the directories marked
DEL (default: list only / dry run). Short form: -y.forkd doctor
Diagnose the host setup. Runs 17 checks and emits fix hints for each non-passing check. Safe to run unprivileged — checks that require root are skipped with a note rather than failing.
Run this first after a fresh scripts/setup-host.sh, whenever forkd fork fails mysteriously, or after a kernel upgrade.
The 17 checks, in order:
| Check | What it tests |
|---|---|
platform | Reads /proc/version; requires Linux |
hw virt | Checks /proc/cpuinfo for vmx (Intel VT-x) or svm (AMD-V) flags |
kvm | Checks /dev/kvm exists and is readable by the current user |
cgroup v2 | Checks /sys/fs/cgroup/cgroup.controllers for a unified cgroup v2 hierarchy |
ip_forward | Reads /proc/sys/net/ipv4/ip_forward; must be 1 |
tap device | Checks /sys/class/net/forkd-tap0 for admin-UP state |
per-child netns | Counts forkd-child-* entries under /var/run/netns |
firecracker | Checks firecracker binary is on $PATH |
firecracker version | Parses firecracker --version; warns below 1.10, fails below 1.5 |
kernel image | Searches ./vmlinux-6.1.141, ./vmlinux, /var/lib/forkd/kernels/vmlinux, /usr/local/share/forkd/vmlinux |
snapshot dir | Checks whether $XDG_DATA_HOME/forkd/snapshots/ exists and counts snapshots |
snapshot dir space | Calls statvfs on the snapshot filesystem; warns below 5 GiB, fails below 1 GiB |
docker | Runs docker info; warns (not fails) if missing — only needed for from-image / parent build |
daemon | GET /v1/snapshots against --daemon-url; warns if unreachable, fails on HTTP 401 |
uffd_wp (v0.4 live BRANCH) | Probes UFFD_FEATURE_WP_ASYNC via forkd_uffd::probe; warns if unavailable (Diff/Full still work) |
memfd_create (v0.4 live BRANCH) | Probes memfd_create syscall availability; warns if unavailable |
hugepages | Reads /proc/meminfo HugePages_Total and HugePages_Free; warns if pool is empty or exhausted |
Controller daemon base URL for the daemon-reachable check. Also read from
FORKD_URL.Bearer token for the daemon check. Also read from
FORKD_TOKEN.forkd bench
Quick latency probe against a live daemon. Runs a representative spawn → exec → branch (diff) → fanout → cleanup cycle and prints per-step timing in a screenshot-friendly format.
Use this to answer “is forkd actually fast on this box?”, for regression checks after a config change, or to validate that benchmark numbers from the README reproduce on your hardware.
Steps performed:
- Spawn 1 source sandbox (
POST /v1/sandboxes n=1). - Exec
sh -c echoviaPOST /v1/sandboxes/:id/exec. - Diff BRANCH the source (
POST /v1/sandboxes/:id/branchwithdiff: true). - Spawn N grandchildren from the branch tag with
per_child_netns. - Kill all children and the source, measure cleanup time.
- Print per-step wall-clock ms and a total.
Snapshot tag to spawn from. Defaults to the first snapshot the daemon reports via
GET /v1/snapshots.Fanout: how many grandchildren to spawn from the branch in step 4.
Whether to use per-child network namespaces for the fanout. Defaults to
true — the fanout step will fail without per-child netns when n > 1 and all children share the same guest IP.Controller daemon base URL. Also read from
FORKD_URL.Bearer token for the controller daemon. Also read from
FORKD_TOKEN.forkd workspace
Stateful long-lived sandboxes that survive suspend/resume across daemon restarts. A workspace tracks a live sandbox by name. When suspended, the sandbox’s current state is snapshotted to a ws-<name>-state tag and the sandbox is killed. When resumed, the daemon restores from that state tag. The source snapshot (--snapshot) is never modified.
All workspace subcommands communicate with the daemon via FORKD_URL / FORKD_TOKEN.
forkd workspace create
Create a new workspace by spawning a sandbox from a snapshot tag.
Workspace name. 1–64 chars, ASCII alphanumeric, dash, or underscore (positional argument).
Snapshot tag to fork from.
Place the live sandbox in its own pre-provisioned netns.
Cgroup
memory.max for the live sandbox in MiB.Controller URL. Also read from
FORKD_URL.Controller bearer token. Also read from
FORKD_TOKEN.forkd workspace suspend
Snapshot the workspace’s live sandbox and kill it. State is preserved under ws-<name>-state; a subsequent resume restores from there.
Workspace name (positional argument).
Use v0.3 Diff snapshot mode for the suspend write. ~200 ms source pause vs seconds for Full.
Also read from
FORKD_URL.Also read from
FORKD_TOKEN.forkd workspace resume
Restore the workspace from its suspended state snapshot.
Workspace name (positional argument).
Also read from
FORKD_URL.Also read from
FORKD_TOKEN.forkd workspace list
List all workspaces tracked by the daemon. Output columns: NAME, STATUS, source=<snapshot tag>, state=<state tag>, live=<sandbox id>.
Also read from
FORKD_URL.Also read from
FORKD_TOKEN.forkd workspace delete
Delete a workspace. Kills the live sandbox if any and removes the state snapshot. Does not touch the source snapshot.
Workspace name (positional argument).
Also read from
FORKD_URL.Also read from
FORKD_TOKEN.forkd where
Print the snapshot data directory path and exit. No flags.
forkd wp-bench
Exercise the UFFD_WP machinery on a synthetic memfd outside of the Firecracker integration. Creates a memfd of the requested size, populates it with a known pattern, arms UFFDIO_WRITEPROTECT, runs the bulk-copy and fault-handler pair, finalizes, and prints timing. Use this to benchmark arm_duration and bulk_copy_clean throughput on a given kernel and filesystem before committing to the full live-BRANCH integration.
Requires Linux x86_64, kernel ≥ 5.7, and either root or sysctl vm.unprivileged_userfaultfd=1.
Size of the memfd region in MiB.
Path to write the snapshot file. Removed after the run by default.