Unkernel: A Real Linux Kernel Compiled to WebAssembly — Architecture and Practical Use
Source: tobias-weiss-ai-xr/unkernel (GPL-2.0-or-later kernel, MIT SDK/page). Live demo: unkernel.dev. npm: unkernel.
1. Executive summary
Unkernel is Linux 7.x built as a single WebAssembly module with a real MMU. The kernel — syscalls, scheduler, memory management, ext4, TCP/IP — is compiled code, not emulated, so programs get Linux's own behaviour down to the edge cases. Only user programs are emulated: unmodified aarch64 (arm64) Linux binaries, so Alpine and Debian packages run as they are.
The result boots Alpine to a shell in roughly 0.3 s after node launches, downloads ~10 MB, runs in 48 MiB of guest memory, and works in Chrome, Edge, Firefox and Safari — including phones — with nothing to install and no server. A zero-dependency TypeScript SDK (MIT) lets you embed the same kernel in Node or the browser, with disks, networking, terminals, vsock, shared memory, framebuffer, audio and (in browsers) GL/Vulkan.
The design's central trick: keep the real Linux kernel running at native wasm speed, but run user code on kwemu, an aarch64 CPU written in Zig and linked into the kernel, which walks the kernel's own Sv48 page tables. Syscalls return straight into the kernel with no emulated trap in between. That gives you faithful Linux semantics and near-native syscall cost — getppid in ~170 ns versus ~1.7 µs under qemu-system.
2. Why not the other three approaches
Most "Linux in the browser" projects pick one of:
- Emulate a whole PC (v86, JSLinux, QEMU wasm). Faithful but slow: every syscall and page fault goes through emulated hardware.
- Emulate the CPU and reimplement syscalls (no real kernel). Fast, but only as much of Linux as the runtime implements.
- Compile programs to wasm (Wasmer WASIX, WebContainers, BrowserPod, or NOMMU Linux). Fast, but native programs must be rebuilt and
fork/MMU-dependent features break or are approximated.
Unkernel keeps the best of each: the real Linux kernel at native wasm speed, under unmodified binaries with a real MMU. The comparison table from the project:
| Approach | Kernel | User space | MMU |
|---|---|---|---|
| Whole-machine emulators | Linux, emulated | unmodified, emulated | emulated |
| Syscall emulators | none (runtime reimplements) | unmodified, emulated | runtime's own |
| POSIX runtimes for wasm | none (runtime provides) | rebuilt for wasm / JS | none |
| Linux without MMU | Linux, native wasm | rebuilt for wasm | none |
| Unkernel | Linux, native wasm | unmodified aarch64, emulated | real page tables |
3. Architecture
- Kernel → wasm. Linux is compiled straight to WebAssembly (
arch/wasm, derived from linux-wasm). The kernel's own code runs at wasm speed. - kwemu. An aarch64 CPU written in Zig, linked into the kernel. It walks the kernel's own page tables, so memory management (fork, mmap, COW, shared memory, threads, signals) is performed by real Linux code, not a reimplementation.
- Syscall path. When a program makes a syscall, kwemu returns to the kernel, which handles it as native wasm. No emulated trap, no emulated kernel mode.
- Task switches via JSPI.
WebAssembly.Suspendinggives the kernel real stacks it can suspend and resume. - JIT for user code. Hot aarch64 blocks are compiled to wasm modules at run time, bit-for-bit with the interpreter. Includes AES/PMULL/SHA instructions OpenSSL uses.
- Paravirtual devices. Small drivers talk to the JS host:
kwblk(block),kwnet(network, user-mode TCP/IP stack in JS),kwfb/kwinput/kwsnd(display, input, sound),kwvsock,kwshm.
The kernel carries a small base system (busybox + unkernel's tools) that mounts a distro image read-only under an overlay root and runs its init; createKernel() without a distro boots that base shell with no download.
4. Performance
Measured under Node:
| Operation | Native | qemu-user | qemu-system | Unkernel |
|---|---|---|---|---|
getppid | 110 ns | 320 ns | 1662 ns | 172 ns |
read 64 B from /dev/zero | 161 ns | 481 ns | 2247 ns | 172 ns |
| pipe write + read | 417 ns | 1032 ns | 7256 ns | 482 ns |
| fork + exit + wait | 73 µs | 537 µs | 1178 µs | 57 µs |
- Boot: kernel reaches
/init~70 ms after start; Alpine prompt appears 0.3 s afternodelaunches; ~10 MB download; 48 MiB guest memory. - Interpreter: ~250–300 M guest instructions/s for integer code under Node.
- JIT: makes real Alpine work 1.6–2.3× faster (ash loop 2.5 s vs 4.0 s;
seq 100000 | sort -r3.1 s vs 7.1 s). - OpenSSL in guest: AES-128-GCM ~100 MB/s, SHA-256 ~160 MB/s.
- CPU-heavy user programs are still well behind native:
apk search~0.8 s,apk add python3~3.4 s.
5. What you actually get
- A real MMU (Sv48 page tables):
fork,mmap, COW, shared memory, threads, signals behave as on hardware. Not a NOMMU port limited tovfork. - Linux's own filesystems: ext4, overlayfs, tmpfs, loop, FUSE, 9p (host mounts). Root is an overlay: read-only distro image under your changes, which go to a persistent ext4 disk; safe mode recovers a broken system.
- Linux's own TCP/IP with DHCP and DNS, reaching the internet through host sockets or a Wisp proxy.
- cgroups, namespaces, userfaultfd, fanotify, TUN — enough for systemd to boot Ubuntu 26.10 to
multi-user.target. - Devices: framebuffer
/dev/fb0, evdev keyboard/mouse/touch, ALSA//dev/dspsound, AF_VSOCK, shared memory with host. - aarch64 user space: ARMv8.0-A with FP/AdvSIMD plus AES, PMULL, SHA1/2/512/3, CRC32, LSE atomics — distribution binaries and OpenSSL's hardware paths run unchanged. Alpine and Debian are first-class.
6. Try it
Browser: open unkernel.dev. ~10 MB download, desktop with a terminal. Changes persist in the browser. URL params: ?mem=512, ?net=0, ?jit=0, ?data=0, ?worker=0, ?cpus=2, ?gl=0, etc.
CLI:
npx unkernel
npx unkernel --distro debian
npx unkernel --distro none
npx unkernel --data my-data.img
npx unkernel --display --sound
npx unkernel --mem 1024 --no-net
npx unkernel --mount .:/work
npx unkernel --forward 8000:80
npx unkernel --timeout 60 --input '{8}uname -a\n{2}poweroff\n'
Exit codes: 0 power off, 1 halt/boot failure, 2 restart, 124 timeout, 253 panic, 254 wasm trap, 255 fatal.
7. Practical paths: embedding Linux in your application
Path A — Drop-in CLI for scripting and testing
Use npx unkernel in CI to run a real Linux environment: typed input on a schedule, timeout, exit code reflects guest outcome. Good for reproducing Linux-only bugs on macOS/Windows, or for integration tests that need apt packages.
Path B — Embed via the TypeScript SDK (Node)
import { createKernel, fetchDistro } from "unkernel";
const vm = await createKernel({ distro: await fetchDistro("alpine") });
vm.onOutput((bytes) => process.stdout.write(bytes));
vm.write("uname -a; poweroff\n");
const { code, kind } = await vm.exited; // 0, "halt"
The distro image downloads once from the GitHub release of the package's version (SHA-256 verified), cached in ~/.cache/unkernel. The kernel ships in the package (unkernel/unkernel.wasm).
Path C — Embed in the browser
Host the distro image yourself (served with range requests) and pass its URL:
const vm = await createKernel({ distro: "/distros/alpine.erofs" });
Networking goes through a Wisp proxy (or directBackend() in Node). Disks can be local ext4 images, http(s) images fetched by range, or a persistent disk in IndexedDB.
Path D — Drive the guest programmatically
vm.exec(cmd, args, { input, cwd, env, user, encoding })— runs on pipes, resolves with{ stdout, stderr, exitCode, signal }.vm.spawn(file, args, { cols, rows, pty })— pty or pipes, withresize(),kill(),close().vm.write()/vm.input/vm.outputReadableStream — console I/O.vm.sync()— flush guest disks;vm.stats()— memory/disk/network/JIT counters.
Path E — Host ↔ guest integration
- Mounts: plain object trees,
MemoryFs(with change notifications),nodeFs(dir)(Node), or your ownFsimplementation. Served over 9p on vsock; guest writes reach the host as they happen. - vsock:
vm.vsock.listen(port)/vm.vsock.connect(port)— byte streams with flow control, no network.vm.connect(port)reaches a guest TCP server on loopback over vsock. - Shared memory:
/dev/shmaccess from host viavm.shm.open/create, with zero-copyviews()when in-place. - Display/sound/input: framebuffer frames, evdev keyboard/mouse, ALSA audio chunks;
createAudioOut()for Web Audio in browsers.
Path F — Graphics and compute in the guest (browsers)
- GL:
gl: truegives the guest Mesa/virgl rendering through the page's WebGL2. Debian:apt install mesa-utils libegl-mesa0 libgles2, theneglinfo. - Vulkan:
vk: truegives a Vulkan 1.2 driver backed by WebGPU (SPIR-V → WGSL viakwvk-naga.wasm). - GPU:
gpu: truewith a kwvirtio kernel gives virtio-gpu with 3D; KMS clients get frames by texture, no readback. - Wayland apps as page windows:
wland footruns a Wayland app whose pixels come straight from guest memory.
Path G — Worker and SMP
worker: true runs the kernel in a worker thread/Web Worker, keeping the event loop free. cpus: N boots an SMP kernel (each CPU in its own thread on shared memory); needs cross-origin isolation in browsers. checkSupport() verifies JSPI and friends before boot.
8. Known limits
- No IPv6, no ICMP beyond the gateway, no UDP on the page beyond DHCP/DNS, no inbound network connections (
vm.connect(),vm.fetch(),--forwardreach guest servers over vsock instead). - Wisp doesn't carry DNS or half-close:
echo hi | nc HOST PORTagainst a server that waits for EOF hangs; names resolve to placeholder addresses in 198.18.0.0/15. - No hardware breakpoints/watchpoints (
gdbwatchpoints are software, single-stepping). - Code that runs only a few times (e.g.
npmstartup) stays on the interpreter; FP/AdvSIMD runs through the interpreter even inside compiled code; without host wasm SIMD, OpenSSL's AES/SHA paths run on the interpreter. - SMP snapshots resume only on as many CPUs.
- A wasm trap in the kernel ends the session.
- One kernel per thread.
- SDK limits: no guest agent beyond terminal sessions;
stop()doesn't shut down cleanly (preferpoweroff); Node-only TS projects need"lib": ["dom"]orskipLibCheck.
9. Build from source
Requires Linux (x86-64 or arm64), Zig 0.16, Node 24, clang 21+ with wasm target. First build ~12 min, ~5 GiB disk.
./setup.sh # check, then build everything
node js/cli.ts # boot your build
pnpm install && pnpm dev # web page at http://localhost:8080
zig build test # emulator tests
Produces vendor/build/bundle/unkernel.wasm and distro images vendor/build/distro/{alpine,debian}.erofs. See kernel/README.md, guest/README.md, and AGENTS.md.
10. Licensing
- Kernel patches, emulator, JIT, patched linker: GPL-2.0-or-later.
- JavaScript SDK and page (
js/,web/): MIT. - npm package:
MIT AND GPL-2.0-only(ships a GPL kernel + base system, plus MIT/GPL guest GL renderer and MIT/Apache-2.0 guest Vulkan translator). - Distro images carry their own package licenses.
- Linux 7.3.4 base plus
kernel/patches/linux(arch/wasmbased on linux-wasm); patches andkernel/tools/fake-llvmare GPL-2.0-only; LLVM patches follow Apache-2.0 WITH LLVM-exception.
11. Conclusion
Unkernel is the most credible "real Linux in the browser" I have seen: it does not reimplement Linux or rebuild your programs, it compiles the kernel to wasm and emulates only user space on a CPU that walks the kernel's own page tables. The payoff is faithful semantics with syscall costs close to native, plus a genuinely usable SDK for embedding a full Linux machine in a web page or Node process.
The honest caveats are the ones in section 8: CPU-heavy work is still far behind native, networking in the browser is Wisp-limited, and a kernel trap kills the session. For interactive shells, scripting, testing, and embedding Linux-backed features in web apps, those trade-offs are very reasonable — and the MIT SDK makes it shippable.
References
- tobias-weiss-ai-xr/unkernel
- unkernel.dev — live demo
unkernelon npm- linux-wasm (Joel Severin) —
arch/wasmorigin - Kernarium — idea origin
- iSH, v86 — emulator/JIT inspiration
- virglrenderer, Mesa — guest GL
- wland, wterm — Wayland compositor / terminals
- Alpine Linux, Debian — booted distributions