Public: anyone can read this; the crew can change it.

Spike: a tiny Linux computer inside the forge process with unkernel (github.c… #17126

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

Spike report only, no code ships: docs/SPIKE-UNKERNEL.md holds the numbers, the licence reading and a recommendation. The git/bun install/test run in Alpine could not be done here. I changed no package.json and no forge.json egress.

Notes

opened this

Spike report only, no code ships: docs/SPIKE-UNKERNEL.md holds the numbers, the licence reading and a recommendation. The git/bun install/test run in Alpine could not be done here. I changed no package.json and no forge.json egress. Nothing in the forge calls out to unkernel yet. I ran bun scripts/gate.ts and --fix, and the gate printed nothing. I did not run tsc or bun test, because the commit is docs only.

What I could not measure. The sandbox cannot reach github.com, and the Alpine image downloads from a GitHub release. So item 2 (git clone, bun install, a test run in Alpine) was not run. I measured the package's bundled busybox base instead.

Numbers (Bun 1.4.4, one loaded shared host, single runs):

  1. Boot under Bun. It boots. Node 20 fails the JSPI check, and Bun 1.4.4 passes it.
    • createKernel takes 171 ms, and the first exec returns about 0.6 s after boot.
    • A cold guest in a worker reaches its first exec in 0.62–0.68 s.
    • Each extra guest in a worker adds about 70–80 MiB RSS at 64 MiB of guest RAM; the first adds about 150.
    • RSS did not fall within 3 s of poweroff, so memory release is not shown.
  2. CPU against native, busybox workloads. The guest is 20–70× slower on CPU-bound work: shell loop 24×, sha256 20×, sort 70×, gzip 48×. Process creation was not slower here (guest 3.4 s against 6.2 s native for 2,000 spawns), but process creation in this sandbox is slow. Expect clone, install and test to be 1–2 orders of magnitude slower. That path is unverified.
  3. Disk in SQLite. A 90-line BlockDevice over bun:sqlite (4 KiB blocks) works.
    • A 20 MB file written in one process was read back after poweroff in a new one.
    • An empty 4 GiB ext4 volume is 2.2 MB on disk, seeded in 145 ms; with the 20 MB file it was 25.5 MB.
    • An Alpine root was not measured.
  4. Host command. forge runs on the host with the bearer token, and the API returned the right JSON to the guest. The token was not found in the guest's env, /proc/*/environ, or command lines and files. The host function is the policy point, so it must allowlist what the guest may ask for.
  5. Web terminal. vm.spawn pty to a Bun websocket worked, with a 35 ms round trip, including a host-command call.

Licence. The kernel is GPL-2.0, and the npm package is MIT AND GPL-2.0-only. Loaded as a separate unkernel.wasm and called only through the MIT SDK, it stays arm's length from forge source. A hosted forge is not distribution. A sold forge that includes the wasm is distribution, so it needs the GPL text and the corresponding source (the pinned release and its patches) or a written offer. It also needs the THIRD-PARTY.md notices, and the wasm must not be embedded in a closed single binary. This is an engineering reading, not legal advice, so have a lawyer confirm before a sold forge ships it.

Decisions and recommendation:

  • (a) Do not replace bwrap/Landlock for agent steps. Isolation is strong, but compute is too slow and the clone/install/test path is unproven. It may suit short shell-bound steps.
  • (b) Per-person computers that sleep and wake in under a second look feasible. State is one SQLite file and the cold wake was under 0.7 s. Memory release after stop and the real Alpine size are still open.
  • (c) Adopt the host-command pattern for keeping secrets out of the sandbox, whatever happens with (a).
  • Follow-up. Repeat items 2 and 3 with Alpine on a host that can reach GitHub (or a mirrored 4 MB image), with clone, install and test timed against native, plus one process per guest to measure memory release. Until that path is under about 5× native, do not ship.

To try it. Read docs/SPIKE-UNKERNEL.md. To reproduce, run bun add unkernel in an empty directory and use the snippets the doc describes.

🤖 Generated with Claude Code

Closes #16837

2 earlier comments
commented

Spike report only, no code ships: docs/SPIKE-UNKERNEL.md holds the numbers, the licence reading and a recommendation. The git/bun install/test run in Alpine could not be done here. I changed no package.json and no forge.json egress. Nothing in the forge calls out to unkernel yet. I ran bun scripts/gate.ts and --fix, and the gate printed nothing. I did not run tsc or bun test, because the commit is docs only.

What I could not measure. The sandbox cannot reach github.com, and the Alpine image downloads from a GitHub release. So item 2 (git clone, bun install, a test run in Alpine) was not run. I measured the package's bundled busybox base instead.

Numbers (Bun 1.4.4, one loaded shared host, single runs):

  1. Boot under Bun. It boots. Node 20 fails the JSPI check, and Bun 1.4.4 passes it.
    • createKernel takes 171 ms, and the first exec returns about 0.6 s after boot.
    • A cold guest in a worker reaches its first exec in 0.62–0.68 s.
    • Each extra guest in a worker adds about 70–80 MiB RSS at 64 MiB of guest RAM; the first adds about 150.
    • RSS did not fall within 3 s of poweroff, so memory release is not shown.
  2. CPU against native, busybox workloads. The guest is 20–70× slower on CPU-bound work: shell loop 24×, sha256 20×, sort 70×, gzip 48×. Process creation was not slower here (guest 3.4 s against 6.2 s native for 2,000 spawns), but process creation in this sandbox is slow. Expect clone, install and test to be 1–2 orders of magnitude slower. That path is unverified.
  3. Disk in SQLite. A 90-line BlockDevice over bun:sqlite (4 KiB blocks) works.
    • A 20 MB file written in one process was read back after poweroff in a new one.
    • An empty 4 GiB ext4 volume is 2.2 MB on disk, seeded in 145 ms; with the 20 MB file it was 25.5 MB.
    • An Alpine root was not measured.
  4. Host command. forge runs on the host with the bearer token, and the API returned the right JSON to the guest. The token was not found in the guest's env, /proc/*/environ, or command lines and files. The host function is the policy point, so it must allowlist what the guest may ask for.
  5. Web terminal. vm.spawn pty to a Bun websocket worked, with a 35 ms round trip, including a host-command call.

Licence. The kernel is GPL-2.0, and the npm package is MIT AND GPL-2.0-only. Loaded as a separate unkernel.wasm and called only through the MIT SDK, it stays arm's length from forge source. A hosted forge is not distribution. A sold forge that includes the wasm is distribution, so it needs the GPL text and the corresponding source (the pinned release and its patches) or a written offer. It also needs the THIRD-PARTY.md notices, and the wasm must not be embedded in a closed single binary. This is an engineering reading, not legal advice, so have a lawyer confirm before a sold forge ships it.

Decisions and recommendation:

  • (a) Do not replace bwrap/Landlock for agent steps. Isolation is strong, but compute is too slow and the clone/install/test path is unproven. It may suit short shell-bound steps.
  • (b) Per-person computers that sleep and wake in under a second look feasible. State is one SQLite file and the cold wake was under 0.7 s. Memory release after stop and the real Alpine size are still open.
  • (c) Adopt the host-command pattern for keeping secrets out of the sandbox, whatever happens with (a).
  • Follow-up. Repeat items 2 and 3 with Alpine on a host that can reach GitHub (or a mirrored 4 MB image), with clone, install and test timed against native, plus one process per guest to measure memory release. Until that path is under about 5× native, do not ship.

To try it. Read docs/SPIKE-UNKERNEL.md. To reproduce, run bun add unkernel in an empty directory and use the snippets the doc describes.

🤖 Generated with Claude Code

commented

This pull adds docs/SPIKE-UNKERNEL.md, the report from a spike that ran unkernel under Bun as a sandbox and a per-person computer. It reports numbers and licence. Nothing ships, and no dependency was added.

The first push failed two docs tests because the new document wasn't listed anywhere. I fixed that by adding it to docs/REFERENCE.md, under "Where the rest is", next to the other spikes. I also added a DOC_LINES entry in src/view/doc_sections.ts, which puts it in the Internals section of /docs. The two failing tests (test/docs-link.test.ts and test/readme-front-door.test.ts) now pass, and tsc is clean. I didn't run the rest of the suite, so the forge's full check on this push is the first full run since those two went red.

The DOC_LINES sentence and heading I wrote for the new document are my own wording. Change them if you'd rather describe the spike differently.

To try it, read docs/SPIKE-UNKERNEL.md, or open /docs and find the entry under Internals.

commented

This pull adds a spike write-up, docs/SPIKE-UNKERNEL.md, measuring unkernel under Bun as a sandbox and a per-person computer, and lists it in the docs index and docs/REFERENCE.md. The previous check failed because the new index line had no test. This push adds the test and a Try: line in the commit message.

  • Test: test/docs-index.test.ts now checks that SPIKE-UNKERNEL.md appears under Internals with its own one-line description. It fails if the DOC_LINES row in src/view/doc_sections.ts is removed.
  • How to try it: open /docs on the preview and look for "Spike: unkernel under Bun" under Internals.
  • Checks: test/docs-index.test.ts passes (5 tests), tsc --noEmit is clean, and the gate's two failures are gone. The gate still prints a note about a comment over 100 columns in src/view/doc_sections.ts. It says nothing needs doing and the nightly rewrap handles it on main.
  • Branch: the branch is behind main, so a diff against main shows many files that this pull did not touch.
  • Not done: I did not rebase.
Sign in to join this conversation.

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

Keyboard shortcuts

Docs