Skip to content

feat(playground): run the VM on unkernel instead of arm64js - #182

Open
raphaelvigee wants to merge 3 commits into
mainfrom
raphaelvigee/playground-unkernel
Open

raphaelvigee wants to merge 3 commits into
mainfrom
raphaelvigee/playground-unkernel

Conversation

@raphaelvigee

@raphaelvigee raphaelvigee commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Replaces the playground's VM (arm64js) with unkernel. unkernel runs a real Linux kernel compiled to WebAssembly and emulates only aarch64 user space. The playground gets much faster.

Benchmark

Same recipe on both VMs: cold boot, the playground's package setup, the heph install and the example builds. Headless Chromium, 1 vCPU, no snapshots, same heph release.

step arm64js unkernel speedup
boot → first exec 2.4 s 0.36 s 6.7×
package setup (apk add) 9.8 s 3.3 s 3×
install heph (75 MB copy + patchelf) 15.9 s 1.0 s 15×
hello: cold / cached 1.68 / 1.08 s 0.22 / 0.14 s ~7.6×
c-app: cold / cached / one change 2.68 / 1.28 / 1.83 s 0.42 / 0.18 / 0.30 s 6–7×
shell loop 100k 28.5 s 3.75 s 7.6×
fork ×500 15.6 s 3.5 s 4.4×
sha256 of 64 MiB 7.9 s 0.46 s 17×
total 91.3 s 14.2 s 6.4×

On the real page the VM boots and finishes setup while heph downloads. It is ready about 2 s after the last byte arrives.

What changed

  • vm.ts boots unkernel's Alpine image and drives setup with exec(). Files are copied in through 9p mounts, and plugins are mounted read-only.
  • terminal.ts (new) bridges xterm and a pty; arm64js shipped its own. When the shell exits, a new one starts.
  • plugins/playground-vm (new) runs at build time and writes to static/playground/ (gitignored):
    • alpine.erofs (4 MB): the root file system, taken from the unkernel release and checked against its SHA-256 index.
    • apk/ (~12 MB): a static subset of the Alpine mirror. It holds the signed APKINDEX of main and community plus the dependency closure of the playground's packages (28 packages, 8.3 MiB). The guest's apk reaches it through fetchRoutes, under a host name only the page answers, and still verifies signatures and checksums. Setup never depends on the internet, and the proxy worker is unchanged.
  • Internet. Everything else goes through the public Wisp proxy wss://anura.pro/, one of the servers unkernel's docs list; unkernel's own server rejects our origins. After setup, apk points at the real Alpine mirror, so apk add go works (16–17 s, 4 of 5 tries succeeded; one failed mid-download). Only one server: unkernel races a list on handshake time, and wisp.mercurywork.shop wins that race but took 3m49 against 17 s for the same install. ?wisp=<url> overrides the server, ?wisp=off cuts the VM off.
  • Slow examples. Every example target starts with sleep 1, so heph's live dashboard has time to show. The welcome text and the examples panel say why. The c-app and monorepo steps still pass --no-tui on purpose, so they print plain logs.
  • Snapshots are gone. Setup now finishes while heph downloads, so they no longer save anything.
  • Kernel wasm: webpack emits the 11 MB kernel as an asset.
  • Lockfile: a targeted swap, arm64js and @arm64js/protocol out, unkernel in. Bindings for darwin-arm64 and linux-x64-gnu are both still present.

Testing

  • lint and build are clean.
  • End to end against the production build (docusaurus serve) in Chromium:
    • Start → ready.
    • All 25 steps of the 6 examples behave as their expect text says, with the sleeps in place. Intended failures fail, --shell works on the pty, and deploy works both through the approval review (Enter, then y) and with --auto-approve.
    • The dashboard renders mid-build, and the VM loads https://example.com and installs go over Wisp.
    • Typing in the terminal works, and so does respawning after exit.
    • Restart boots a second kernel in the same page in 4.9 s.
    • No failed requests.

Worth a look before merging

  • New dependency. unkernel's first release was 2026-11-12 and it publishes daily prereleases. This PR pins 0.2.0-261127-3b71fa5 exactly (published 2026-11-27); that is the version benchmarked here.
  • License. The kernel and emulator wasm are GPL-2.0, and the SDK is MIT. We would now serve the unmodified GPL binary from this site; arm64js (MIT) loaded its runtime from its own CDN.
  • Browsers. The VM needs WebAssembly JSPI: Chrome/Edge 137+, Firefox 153+, Safari 27+. That is wider than before, and the error message now says so. Firefox and Safari are untested.
  • Third-party proxy. The Wisp operator sees which host names and ports the VM connects to, and any plain-HTTP content; TLS stays end to end. If it goes down, the examples still work and only internet access is lost.
  • Build dependency. The build now fetches from dl-cdn.alpinelinux.org and from unkernel's GitHub release. Both are cached in website/.playground-cache/.
  • Alpine branch. ALPINE_BRANCH (v3.24) in packages.ts must match the unkernel image's Alpine release. A mismatch fails loudly at apk add.

🤖 Generated with Claude Code

unkernel runs a real Linux kernel compiled to WebAssembly, with only
aarch64 user space emulated. On the playground's own setup and examples
it is about 6x faster end to end than arm64js (14 s vs 91 s for the same
recipe in headless Chromium), and 6-8x faster per heph build.

- vm.ts: boot unkernel's Alpine image, drive setup with exec(), copy
  files in through 9p mounts, mount plugins read-only.
- terminal.ts: xterm <-> pty bridge (arm64js shipped its own); a shell
  that exits is replaced.
- plugins/playground-vm: at build time, copy the Alpine image out of the
  unkernel release and write a static subset of the Alpine mirror (the
  closure of the packages the VM installs, with the signed indexes) to
  static/playground/. The guest's apk reaches it through fetchRoutes, so
  the VM never touches the internet and needs no proxy changes.
- Drop the snapshot logic: setup now finishes while heph downloads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

⚡ Cloudflare Pages preview

Preview https://b5fcd645.hephbuild.pages.dev
Commit 4a6e64a

raphaelvigee and others added 2 commits November 28, 2026 02:00
…size

Cloudflare Pages previews ignore Range requests, and unkernel reads a
distro URL lazily with them, so the VM failed to boot there. The image
is 4 MB: fetch it once and hand unkernel an in-memory disk.

The idle text said the first start downloads "about 200 MB"; the latest
release alone is 290 MiB. Compute it from the selected release's asset
sizes plus the VM's own ~27 MB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…targets

The VM can now reach the internet: TCP goes over wss://anura.pro/, one of
the public Wisp servers unkernel's docs list (unkernel's own only admits
its own origins). Setup still installs from this site's mirror, under a
host name only the page answers, so a slow or unreachable proxy can't
break a start; afterwards apk points at the real mirror, so `apk add go`
works. Only one server: unkernel races a list on handshake time, and
wisp.mercurywork.shop handshakes faster but moved `apk add go` in 3m49
against 17s. `?wisp=<url>` overrides it, `?wisp=off` cuts the VM off.

Every example target now starts with `sleep 1`, so builds last long
enough to watch heph's live dashboard; the welcome text says why.

Also: the deploy step's hint now says Enter opens the review before `y`,
and the intro no longer claims nothing leaves the machine.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant