TheDocumentation 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.
@deeplethe/forkd TypeScript SDK is the Node.js 18+ client for the forkd-controller daemon. It exposes two classes: Controller for host-side VM lifecycle management (spawning, branching, killing sandboxes and managing snapshots) and Sandbox as a higher-level single-VM wrapper with an E2B/Daytona-compatible shape. Both classes are fully typed — type definitions are sourced from the wire-level api.rs shapes and kept in sync with the Python SDK. The fetch global introduced in Node 18 is used by default; older Node versions can pass a custom fetch implementation via ControllerOptions.
Installation
fetch).
ControllerOptions
Options accepted by theController constructor.
Daemon base URL. Resolved in order:
options.baseUrl, the FORKD_URL environment variable, then the hardcoded default. Trailing slashes are stripped.Bearer token sent as
Authorization: Bearer <token>. Defaults to the FORKD_TOKEN environment variable. Required only when the daemon was started with --token-file.Per-request timeout in milliseconds. Branching a large source VM can take several seconds; the default is generous. An
AbortController enforces this on every fetch call.Custom
fetch implementation. Defaults to globalThis.fetch. Provide undici’s fetch for test scenarios that need request recording, or a polyfill for Node versions prior to 18.Controller
Controller is the primary client for the forkd-controller REST API.
Constructor
Error if no fetch implementation is available (Node 17 or earlier without a polyfill).
Snapshot methods
listSnapshots
GET /v1/snapshots — returns every snapshot registered with the daemon.
Array of
SnapshotInfo objects. See type definitions for the full shape.deleteSnapshot
DELETE /v1/snapshots/:tag — removes a snapshot from the registry and deletes its on-disk files.
The snapshot tag to delete.
Sandbox methods
spawnSandboxes
POST /v1/sandboxes — fork n children from a registered snapshot tag.
Name of a registered snapshot to fork from. Must exist in
listSnapshots().Number of child sandboxes to spawn, 1–1000.
When
true, each child is placed in a dedicated network namespace forkd-child-<i>. The host must have run scripts/netns-setup.sh N beforehand.Sets the cgroup
memory.max for each child in MiB.v0.2.5+. When
true, each child performs a throwaway snapshot immediately after restore to fault in all guest pages. Trades ~170 ms / 512 MiB of extra spawn time for predictable BRANCH latency. Useful when fanning out 3+ sandboxes from the same source with a BRANCH SLO.v0.4+. Boots the sandbox with a memfd-backed RAM region so later BRANCHes can use
mode: "live" (UFFD_WP). Requires Linux kernel 5.7+ and the vendored Firecracker fork.v0.4+. Backs the memfd with 2 MiB hugepages. Only meaningful with
liveFork: true. Reduces TLB pressure during spawn-many and live BRANCH bulk-copy. Requires free hugepages in /proc/meminfo.Array of
SandboxInfo objects, one per spawned child.listSandboxes
GET /v1/sandboxes — returns every live sandbox the daemon tracks.
Array of
SandboxInfo objects.getSandbox
GET /v1/sandboxes/:id — fetch metadata for one sandbox.
The sandbox id (e.g.
"sb-67a1b3-0000").A single
SandboxInfo object.killSandbox
DELETE /v1/sandboxes/:id — terminate one sandbox.
The sandbox id to terminate.
branchSandbox
POST /v1/sandboxes/:id/branch — pause the source, write a snapshot, resume. Returns the new snapshot. Pass its tag to spawnSandboxes to fan out grandchildren that inherit the source’s exact state.
Id of the sandbox to branch from.
Optional tag for the new snapshot. When unset, the daemon generates
branch-<sandbox-id>-<unix-ts>.v0.4+ canonical mode selector (
"full", "diff", or "live"). Prefer this over the legacy diff boolean. Mutually exclusive with diff — passing both yields HTTP 400."full"— copy entire guest RAM (0.5–8 s pause). Default for v0.x."diff"— Firecracker Diff snapshot (v0.3+). ~200 ms idle source; 6–15× speedup on typical agent workloads."live"— UFFD_WP (v0.4+). Sub-50 ms source pause. Source must have been spawned withliveFork: true.
Legacy. Equivalent to
mode: "diff". Kept for v0.3.x daemon compatibility. Mutually exclusive with mode.v0.3+. Measurement-only hook. Takes a Diff snapshot inside the Full pause to report what diff would have cost, without changing semantics.
v0.4+, only meaningful with
mode: "live". Default true blocks until the background copy finishes (status: "ready"). Set to false to return after the source resumes (~10 ms); poll listSnapshots() for status: "ready".A
SnapshotInfo object. When mode: "live" with wait: false, the initial status is "writing".execCommand
POST /v1/sandboxes/:id/exec — run a subprocess inside a sandbox.
The target sandbox id.
Argv list (e.g.
["python3", "-c", "print(2+2)"]).Maximum seconds to wait for the command.
{ stdout: string, stderr: string, exit_code: number }evalCode
POST /v1/sandboxes/:id/eval — evaluate code against the sandbox’s warmed PID-1 process.
The target sandbox id.
Python expression to evaluate. Pre-imported packages like
numpy are in scope if the parent snapshot included them.{ result: unknown, error: string | null, exit_code: number }pingSandbox
POST /v1/sandboxes/:id/ping — round-trip health check to the in-guest agent.
The target sandbox id.
An object whose shape depends on the recipe. Guaranteed to contain at least
pong.Sandbox
Sandbox is a higher-level wrapper around a single live sandbox. Its shape mirrors E2B and Daytona SDKs so existing agent code can swap in forkd with minimal changes.
Sandbox.create
Sandbox instance that owns it. The most common entry point.
Sandbox.with (recommended)
Constructor (low-level attach)
Controller.spawnSandboxes. Useful when you fan out many children and want to wrap each one individually.
Instance methods
exec
Controller.execCommand.
eval
Controller.evalCode. Throws Error when the eval returns an error.
ping
branch
tag to Controller.spawnSandboxes to fan out grandchildren.
kill
Type definitions
All types are re-exported from@deeplethe/forkd. Wire-level field names use snake_case (matching the daemon’s REST API); TypeScript argument names use camelCase where noted.
SandboxInfo
SnapshotInfo
BranchMode
| Value | Pause window | Notes |
|---|---|---|
"full" | 0.5–8 s | Copies entire guest RAM. Default for v0.x. |
"diff" | ~200 ms | Firecracker Diff snapshot (v0.3+). 6–15× speedup on typical workloads. |
"live" | sub-50 ms | UFFD_WP (v0.4+). Source must be spawned with liveFork: true. |
SpawnOptions
Wire-level body for POST /v1/sandboxes. Used internally by Controller.spawnSandboxes.
BranchOptions
ExecResult
EvalResult
PingResult
recipes/.
ControllerError
Thrown on any non-2xx response from the daemon.Python vs TypeScript comparison
- Python
- TypeScript