Spike: a tiny Linux computer inside the forge process, unkernel (#16837)

Status: measured, behind no door. Nothing ships; no dependency was added to package.json. Every figure below was taken on this crew sandbox (one shared host, Linux 6.12, Bun 1.4.4, unkernel 0.3.0-261130-3ef745b installed with bun add in a scratch directory). Timings are single runs on a loaded shared host: read them as orders of magnitude.

What could not be measured, and why

The Alpine image is not in the npm package. fetchDistro("alpine") downloads it from a GitHub release, and this sandbox reaches the forge, the registry and its own app only (github.com answers 403 blocked-by-allowlist). So item 2 as written (git clone, bun install, a test run in Alpine) was not run. What ran instead is the package's bundled base system (busybox, no apk, no git, no network). Item 2's CPU cost is therefore stated from busybox workloads, not from git/bun. Someone with GitHub egress should repeat it with npx unkernel --distro alpine --timeout ...; the numbers below say what to expect.

1. Does it boot under Bun 1.4.4?

Yes. The README names Node, and Node 20 (this host's) fails checkSupport() for lack of JSPI (engines: node >= 24). Bun 1.4.4 has WebAssembly.Suspending/promising and checkSupport() returns ok: true. createKernel, exec, spawn, host commands, vsock and a custom block device all worked unchanged.

measured
createKernel() resolves (base shell, 2 GiB default RAM)171 ms
first exec returns+428 ms (≈0.6 s to a usable guest)
createKernel + custom disk, 64 MiB guest, warm cache135 to 226 ms
cold start of a fresh guest in a worker, to first exec620 to 680 ms
Bun RSS before any guest41 to 55 MiB
one guest, 128 MiB RAM, after a CPU benchmark154 MiB (≈ +100)
1, 2, 3 guests in workers (64 MiB each), RSS194, 272, 339 MiB: ≈ 70 to 80 MiB per extra guest; the first costs ≈ 150 MiB (module compile and JIT)

One kernel runs per thread, so several guests need worker: true. After poweroff the RSS did not fall back within 3 s (282 MiB against 41 MiB at start): whether a stopped guest returns its memory is not shown; a process per guest would settle it.

2. CPU cost against native (busybox workloads, same host)

Guest = busybox ash on the aarch64 emulator with the JIT on. Native = dash and GNU coreutils on the host, so the ratio flatters native a little.

workloadguestnativeratio
shell loop, 100 000 iterations26.0 s1.1 s≈ 24× slower
sha256sum of 32 MiB8.5 s0.43 s≈ 20×
`seq 200000 \sort -r`16.5 s0.23 s≈ 70×
gzip of 16 MiB7.9 s0.16 s≈ 48×
2 000 × /bin/true (fork+exec)3.4 s6.2 sguest faster here; process creation in this sandbox is slow

That is far worse than the README's "1.6×/2.3× over the interpreter", and it matches its own warning that "CPU-heavy programs are well behind native". Expect git clone (zlib, SHA-1) and bun install (a JS engine under emulation, or Bun's x86 binary under box64/qemu-user, neither tested) to be one to two orders of magnitude slower than native. A test run of the forge's size is not a light agent step in this guest. Process creation, syscalls and I/O are cheap; compute is not.

3. Disk as blocks in a SQLite table

Works, and persists across stop and start. A 90-line BlockDevice over bun:sqlite (blocks(n INTEGER PRIMARY KEY, d BLOB) WITHOUT ROWID, 4 KiB blocks, one transaction per guest write, flush checkpoints the WAL, discard/writeZeroes delete rows, flags = F_FLUSH|F_DISCARD|F_WRITE_ZEROES, persistent: true) was attached as the data disk.

4. A host command, and the token never enters the guest

commands: { forge: async (c) => fetch(API + c.args.join("/"), { headers: { authorization: "Bearer " + TOKEN } }) }. In the guest, forge repos/trevato/forge/issues/16837 returned the API's JSON ({"ok":true,...}: the server saw the right bearer). Checked inside the guest: env | grep -c SECRET 0; every /proc//environ 0 matches; a recursive grep of /proc//cmdline /run /etc /home /tmp for the token 0 matches (after excluding the grep's own command line, which first gave a false 4). /run/kw/bin/forge is a symlink to kwbox; the function body and the token stay in the host process. The guest sees arguments, stdin, cwd and the output the host returns, so the host function is the policy point: it must allowlist subcommands and paths, because anything it will fetch for the guest the guest can ask for.

5. Web terminal wired to one guest

vm.spawn("sh", [], { cols, rows }) gives a pty with output, write, resize. A Bun.serve websocket piped sh.output to the socket and socket messages to sh.write: a WebSocket client sent echo $((6*7))-from-guest; forge x and got 42-from-guest and the host-command JSON back in 35 ms. No network between page and guest; vsock (vm.vsock.listen/connect, vm.connect(port)) is available for anything else. The forge's own terminal door was not touched.

Licence

Decides

(a) Replace bwrap/Landlock for light agent steps where namespaces are missing? No, not as the default. Isolation is the strongest of any option here (no host syscalls, no host filesystem, no host network unless given), and it needs no kernel privilege. But compute is 20 to 70× slower than native and the clone/install/test path was not shown to work at all (no image reachable). Good fit: short, I/O or shell-bound steps (read files, run a linter script, call forge host commands); poor fit: anything compiling, installing or running the test suite. Revisit with GitHub egress and a real git+bun run.

(b) Per-person or per-repo computers that sleep at zero cost and wake in under a second? Yes in principle, shape proven. State is one SQLite file (2.2 MB empty), a stopped guest is a closed file, a cold wake in a worker was 0.62 to 0.68 s, a guest costs 70 to 80 MiB of RSS while awake (≈150 for the first). Open: RSS release after stop (not shown), and the real size with Alpine.

(c) The host-command pattern for keeping secrets out of the sandbox? Yes, adopt it regardless of (a). Shown: the token stays in the host, the guest cannot read it from env, /proc or files. The cost is that the host function must itself validate and allowlist.

Recommendation

Do not ship. One follow-up, small: repeat items 2 and 3 with Alpine on a host that can reach GitHub (or mirror the 4 MB image into a blob we control and distro: it by path), with git clone, bun install, bun test timed against native, and a one-process-per-guest run to measure memory release. Until the CPU numbers for that path are under ~5× native, keep bwrap/Landlock for agent steps and use unkernel only as a candidate for the per-person "computer" and the host-command pattern. No egress entry was added: nothing in the forge calls out to it yet.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs