English | 简体中文
RFB (Runtime/Resource/Filesystem Boundary) is a sandbox-oriented Rust workspace that defines typed contracts, transports, and runtime integrations between a host and guest VMs. It is not a chat service, a model proxy, or an application session layer.
[dependencies]
rfb-sdk = "0.0.1"
rfb-adk = "0.0.1"
# Only needed for the guest/Firecracker runtime:
rfb-runtime = { version = "0.0.1", default-features = false, features = ["host-vsock"] }CLI: cargo install rfb-sdk --features cli (binary: rfb-cli). The prebuilt linux-x64 rfb-cli binary is also distributed as a binary-only package (no wrapper code):
dotnet add package Rfb.Cli # NuGet (binary in tools/, copied to output)
npm install -g rfb-cli # npm (bin entry points straight at the ELF)One TOML file describes the image — interpreters, offline packages, prebuilt Rust apps, extra files — and rfb-cli image build-script drives the whole chain (static runtime build → rootfs assembly → verification):
schema = "rfb-build/v1"
mode = "zeroboot-zbrt"
output = "out/my-sandbox.ext4"
force = true
[interpreters]
python = true # /bin/python3 (embeds RustPython)
lua = true # /bin/lua (embeds mlua 5.4)
[packages]
py-site = "sites/py" # offline pure-Python packages -> /usr/lib/python3/site-packages
lua-lib = "sites/lua"
[rust]
apps = ["hello"] # prebuilt musl binaries -> /usr/local/bin
[files]
"assets/banner.txt" = "/etc/motd"See docs/example-build.rfb for the annotated reference script. Interpreter features are fail-closed: a runtime built without rustpython/mlua is rejected at image build time instead of installing dead applets.
Published crates contain Rust sources and crate resources only — no Firecracker binary, Linux kernel, ext4 images, snapshots, or forkd service. Those must be provisioned explicitly by the deployment system.
| Crate | Responsibility |
|---|---|
rfb-sdk |
Minimal sandbox API, capability / filesystem / guest protocol abstractions; optional forkd, ZBRT, and rfb-cli integration. |
rfb-adk |
Adapts RFB sandbox capabilities as ADK (adk-rust) agent tools; assembles a ready-to-run agent; the application owns the model. |
rfb-runtime |
RFB1 guest/runtime, workspace executor, vsock, Firecracker controller, and runtime tests; also hosts library code used by build/acceptance flows. |
Dependency direction: rfb-adk / rfb-runtime → rfb-sdk; rfb-sdk never depends on adk-rust. The application owns agents, prompts, models, HTTP/SSE, credentials, and session storage.
The same sandbox surface ships as:
| Language | Package |
|---|---|
| Python | rfb-sdk (import rfb_sdk) |
| Java | io.github.cricle:rfb-sdk (Maven Central) |
| C#/.NET | Rfb.Sdk (NuGet) |
| Node.js | rfb-sdk (import { RfbClient } from 'rfb-sdk') |
All four suites (Python / C# / Java / Node.js) are exercised end-to-end in CI on a clean Debian 12 container (see sdk/e2e/debian-e2e.sh).
By default rfb-sdk enables no backend. forkd enables the TCP/NDJSON forkd client, zeroboot enables ZBRT, and cli enables every backend plus the rfb-cli binary. rfb-runtime defaults to core; guest adds the guest/vsock side, host-vsock the host side, forkd the guest forkd agent, firecracker the Linux/KVM controller, and cli everything the CLI needs.
tokio-vsock, KVM ioctls, and the Firecracker controller are Linux-only. Windows builds core/CLI (no Linux KVM/vsock); macOS builds everything that does not require a Linux backend. Real-VM acceptance needs Linux/WSL, KVM, and matching Firecracker, kernel, and rootfs assets. MSRV is Rust 1.93 (edition 2021), tracked by Cargo.lock.
cargo add rfb-sdk
cargo test -p rfb-sdk
cargo test -p rfb-runtime --no-default-features --features core
cargo build -p rfb-sdk --features cli
rfb-cli doctor --json # host capability reportProtocol lines — RFB1 (framed vsock), forkd (TCP/NDJSON), and ZBRT (ZeroBoot binary frame) — are not interchangeable. Missing capabilities must fail closed.
The ZeroBoot provider keeps one VM but opens a pool of ZBRT connections into it, because the V1 contract allows one active command per connection. Four environment variables size that VM for a host (defaults in parentheses): RFB_ZBRT_VM_MEM_MIB (128; the measured Firecracker floor is 48), RFB_ZBRT_VM_VCPU (1), RFB_ZBRT_SESSIONS (8, the number of commands that can run at once), and RFB_ZBRT_SNAPSHOT_SHARDS (2, only meaningful with hot start). rfb-ben zbrt --vcpus 1,2 --mem-mib 512 measures the resulting scaling curve on a real KVM host.
Setting RFB_ZBRT_SNAPSHOT_DIR=<dir> (on tmpfs) turns on snapshot hot start: the provider boots its parent VM once, pauses it, and snapshots it into <dir>/parent/; every later sandbox restores from that snapshot instead of paying a cold boot (~1 s -> a few hundred ms). The snapshot carries an identity fingerprint (kernel, rootfs, machine shape, port), so a config change rebuilds it automatically. Children share the parent's memory file copy-on-write and its rootfs image (guest writes land on the per-VM workspace tmpfs), so neither a memory nor an image copy is paid per create. Note: the vsock relay path is baked into the snapshot by the patched Firecracker build in resx/, so hot-mode creates serialize per snapshot dir; RFB_ZBRT_SNAPSHOT_SHARDS=N (default 2) gives each shard its own parent snapshot and lock, running restores fully in parallel (measured: 100 concurrent creates, 100/100 ok — ~106 ms/create at 2 shards, ~54 ms at 4 shards; gated in CI by tests/zeroboot_concurrency.rs). Snapshot files are owner-only (0700/0600) — memory.bin contains the VM's full memory.
rfb::cluster::ClusterProvider spans N forkd controller nodes (forkd-controller serve on each host — no extra server component): it schedules sandbox creation to the least-in-flight healthy node (or round-robin), fails over on transport errors, 5xx, and undecodable responses, trips a node after 3 consecutive failures, and lets it back in with one lazy half-open probe per recovery_interval (default 30 s; probe() checks on demand, immediately). 4xx propagates to the caller with no failure strike and no failover (no silent double-create); a transport/decode failure reconciles the node's sandbox list and deletes a unique orphan (a miss is preferred over a wrong delete). The returned handle releases its in-flight slot on drop (RAII, no manual release). preflight() verifies every node has the snapshot ready/bootable with matching digests; list_all() + delete_on() find and clean up orphans after an owner crash. Exec/stream/filesystem traffic goes directly to the sandbox's guest address; teardown routes to the owning node. All nodes boot the same snapshot tag. See sdk/BACKEND_SETUP.md §7 and rfb/tests/cluster.rs.
ZeroBootSandbox::fork(self) checkpoints a live VM (pause → full snapshot) and restores TWO fresh VMs from that checkpoint, returning (continued original, fork) — both inherit the full live state, because the workspace tmpfs is guest memory captured by the dump (real-VM verified: files written before the fork are visible in the fork and in the fork of the fork). One fork costs ~0.5-1 s (the patched Firecracker build has no incremental diff, unlike forkd's live-fork), the checkpoint dir is shared-owned by both siblings and removed with the last one, and the sandbox is forkable only in hot mode (RFB_ZBRT_SNAPSHOT_DIR). See sdk/BACKEND_SETUP.md §6b-4 and rfb/tests/zeroboot_fork.rs.
Protocol code, build code, image manifest examples, and docs live inside the git/crates.io boundary. Large, platform-specific artifacts are deliberately NOT published as crate dependencies: Firecracker binaries, Linux kernels, ext4 rootfs images, snapshots, forkd agent images, runtime static binaries, logs, and build directories are external artifacts. A controlled artifact store or deployment pipeline downloads them per target platform, verifies SHA-256, and injects them via absolute paths or environment variables (for example RFB_RUNTIME_BIN, FORKD_ROOTFS).
This repository keeps resx/firecracker/firecracker-v1.16.1-x86_64.tgz as the only full Firecracker release asset, verified with sha256sum -c resx/firecracker/firecracker-v1.16.1-x86_64.tgz.sha256. The bundled LICENSE, NOTICE, and THIRD-PARTY files must accompany any redistribution. Never commit credentials, real snapshots, or user workspace content.
- CI — every PR and non-main push: Rust checks (fmt, clippy, tests, docs with
--all-features, boundary checks) plus full SDK builds and tests (Python / C# / Java / Node.js) in a clean Debian 12 container. - Real-VM E2E — pushes to
main: boots the real Firecracker/forkd stack on a KVM runner, creates a snapshot from the forkd-agent rootfs, and runs the full#[ignore]-gated real-VM test suite. - Release — pushing a
vMAJOR.MINOR.PATCHtag publishesrfb-runtime→rfb-sdk→rfb-adkto crates.io,rfb-sdkto PyPI,io.github.cricle:rfb-sdkto Maven Central (GPG-signed), andRfb.Sdkto NuGet, andrfb-sdk(TypeScript) plus therfb-clibinary to npm, then attaches therfb-clibinary and SHA256SUMS to a GitHub Release. Publishing is idempotent: already-published artifacts are skipped on re-runs.
See docs/RELEASE.md for the full release pipeline, one-time setup and a failure quick-reference.
A forkd-only minimal variant of this workspace is generated mechanically — never hand-maintained:
scripts/split-minimal.sh --check /tmp/simple # surgery + compile gate- The minimal tree is regenerated from the latest main every time (no
long-lived branch, no merges, no conflicts): deleting zeroboot,
ben, and their hooks is a deterministic transformation kept inscripts/split-minimal.sh. - Rules for main-branch changes (mandatory — this is what keeps the surgery
working):
- zeroboot code lives only in zeroboot files (
rfb/src/zeroboot/,rfb/src/cli/zeroboot.rs,rfb/src/cli/zeroboot_backend.rs,rfb/tests/zeroboot_*,rfb-runtime/src/zeroboot_connection.rs,rfb-runtime/src/zeroboot_guest.rsand their tests). Never spread zeroboot logic into shared modules — put it in those files and expose a small hook. - Shared hooks stay one-or-few lines (
cli/mod.rsmodule registration,commands.rs'sZeroboot { .. }variant,dispatch.rs's forwarding arm,lib.rs's module declarations, thezerobootfeature line in bothCargo.tomls). The surgery deletes exactly those lines; keeping them few and contiguous is what makes that reliable. - New zeroboot files must be added to
REMOVEinscripts/split-minimal.shin the same commit that adds them. - After touching anything zeroboot-related, run
scripts/split-minimal.sh --checklocally — it fails loudly on leftover references (whitelist: the sharedzeroboot_protocolwire, thezeroboot-zbrtrootfs image format, the backend factory's fail-closed branch) or on a broken minimal compile.
- zeroboot code lives only in zeroboot files (
firecracker.rs(the Firecracker HTTP-API driver) andprotocol.rs(the ZBRT wire format) are shared with the RFB1 path and are kept by the surgery; only the ZeroBoot provider/session layer is removed.
MIT — see LICENSE-MIT.