Booting Linux Inside WebAssembly: Rootless 73 MiB Sandboxes with Freeze-on-Ask Auditing
TL;DR: unkernel-rs is a disposable Linux computer for AI agents and untrusted code: a native Rust binary that boots an unmodified Linux 7.3.4+ kernel inside
wasmtimeon Linux, macOS, and Windows — completely rootless, with zero Docker, zero WSL2, zero/dev/kvm, and zero Node.js. Cold boot takes ~260 ms at 72.9 MiB RAM, runs inside unprivileged Kubernetes pods or plain Windows PowerShell, and lets the host audit, freeze mid-action, and block suspicious network or.envaccess from outside the guest kernel. (Looking for the newer 3-line Pythonpip install unkernel-rswalkthrough andv0.9.0–v0.10.0features? See pip install a Real Linux 7.3 VM.)
In Part 5 of this series, I locked down AI agents with Linux Landlock and nono. OS sandboxes have near-zero overhead, but they share the host kernel, cannot grant disposable fake root to apk add or apt-get install tools, and differ across Linux, macOS, and Windows.
MicroVMs like Firecracker solve isolation cleanly — until you are inside a nested VM, a CI runner, an unprivileged Kubernetes pod, a Mac with no /dev/kvm, or a Windows laptop without WSL2/Hyper-V.
Then I tried pithings/unkernel: a real Linux 7.x kernel compiled to WebAssembly. Upstream runs it on Node.js + V8’s experimental JSPI (~232 MiB RAM). I wanted to see what happens if you host that same kernel directly on native Rust + wasmtime, drop Node.js, wrap Linux hosts in Landlock, and turn the Wasm host boundary into an untamperable security monitor.
That experiment became unkernel-rs (v0.4.0, MIT/Apache-2.0).
Why Rootless Linux-in-WebAssembly?
Everything runs as an ordinary unprivileged user process — no root daemon, no CAP_SYS_ADMIN, no /dev/kvm, no Hyper-V/WSL2, no Docker socket. Inside the sandbox, an agent or untrusted npm install still gets disposable fake uid=0 (root) and can install packages or run rm -rf / without touching your host.
| Dimension | nono / Landlock | Docker | KVM / Firecracker | unkernel-rs |
|---|---|---|---|---|
| Root daemon / KVM / Hyper-V | No | Root daemon (or WSL2/VM) | Yes (/dev/kvm) | No (100% rootless) |
| Separate Linux kernel | No | No | Yes | Yes (Linux 7.3.4+ in Wasm) |
Fake root + apk/apt | No | Yes | Yes | Yes |
| Host RAM (idle VM) | ~0 MiB | ~20–50 MiB + daemon | ~5–30 MiB + guest | 72.9 MiB |
| Cold boot → command | < 5 ms | ~150–400 ms | ~125–300 ms | 254–279 ms |
| Guest CPU speed | Native | Native | Near-native | Emulated aarch64 + JIT |
| Linux + macOS + Windows | Linux only | Needs Linux VM on Mac/Win | Linux KVM only | Yes (single native binary) |
Three independent isolation rings stack together:
To avoid V8’s unstable JSPI stack-switching, unkernel-rs unpacks the bundled SMP kernel patch into wasmtime::SharedMemory and maps cooperative Linux kthread switches across per-task Stores. After the first AOT compile, .cwasm loads in 5–6 ms.
Try It in 30 Seconds
Prebuilt binaries for Linux (x86_64 / aarch64), macOS (arm64), and Windows (x86_64 .zip) are on GitHub Releases, or grab the full copy-paste commands (including Windows PowerShell) in the quickstart snippet.
# 1. Fetch & SHA-256 verify pinned unkernel.wasm + Alpine rootfs
./unkernel-rs fetch
# 2. Air-gapped, Landlock-sandboxed Linux command (zero network, zero host FS)
./unkernel-rs exec --sandbox -- uname -a
# 3. Install jq into a sparse ext4 disk with domain-allowlisted NAT (LAN blocked)
./unkernel-rs exec --sandbox --net --allow-host alpinelinux.org \
--disk ./tools.ext4 -u root -- apk add --no-cache jq
# 4. Boot clean air-gapped copies forever (4 KiB in-memory COW; host disk untouched)
./unkernel-rs exec --sandbox --offline \
--disk ./tools.ext4 --disk-snapshot -- jq --version
On Windows (PowerShell, no WSL2 or Hyper-V needed), the exact same binary runs natively with NTFS sparse disks (FSCTL_SET_SPARSE) and drive-letter 9P mounts (-m C:\work:/workspace:ro):
.\unkernel-rs.exe fetch
.\unkernel-rs.exe exec -m C:\work:/workspace:ro -- sh -c "uname -a && ls /workspace"
Bullet-Time Auditing & Freeze-on-Ask Approvals
Because every mounted file op (9P2000.L) and every network packet (user-space NAT) crosses the host Rust runtime outside Wasm, unkernel-rs can observe and gate behavior in a way even root inside the guest cannot see or tamper with.
That makes it ideal for supervising coding agents or detonating suspicious packages — think Shai-Hulud style supply-chain attacks hunting .env, .npmrc, or ~/.ssh/* and phoning home:
./unkernel-rs exec --sandbox \
-m ./untrusted-repo:/workspace:rw \
--audit --audit-file ./audit.jsonl \
--ask-net --ask-fs-write --ask-sensitive --freeze-on-ask \
-- sh -c 'cat /workspace/.env; wget -qO- https://example.com'
- Pre-socket TCP
SYNgating (--ask-net): Holds outbound connections before any hostTcpStreamopens. Denying injects a TCPRSTwith zero packets leaving your machine; allowing still logs DNS, TLSClientHelloSNI (no MITM cert), HTTP request lines, and TX/RX bytes. - Credential & write gates (
--ask-sensitive,--ask-fs-write): Intercepts.env*,.npmrc,.ssh/*,.aws/*,.kube/*,*.pem, and mutating 9P ops — includingO_RDWR,truncate, andmv .env benign.txtrename bypasses. - Whole-VM freeze (
--freeze-on-ask): Useswasmtimeepoch interruption to halt every guest kernel thread and pauses guest monotonic time (/proc/uptime, timers) while you judge.
In daemon mode (unkernel-rs serve), the exact same events stream as real-time NDJSON while external controllers send {"approve": 1, "decision": "deny_once"}, {"pause": true}, or {"resume": true} concurrently.
”Catch Me If You Can”: Red-vs-Blue WebUI Demo
The repo ships a zero-dependency Cargo example that launches a split-screen or two-player Red-vs-Blue game against a decoy workspace stocked with fake canary secrets:
cargo run --release --example catch_me_if_you_can
# Two-player LAN mode (/red vs token-protected /blue?token=...):
cargo run --release --example catch_me_if_you_can -- --bind 0.0.0.0:8787
Here is the moment Red Team runs cat /workspace/.env — the VM freezes (FROZEN · CLOCK STOPPED), taint jumps to SENSITIVE, and Blue Team receives a live approval card before a single byte of the secret enters the guest:

Blue Team clicks Deny Once (Permission denied, zero leak). Red Team then probes 192.168.1.1 (hard-blocked deny_lan in 12 ms) and tries an outbound HTTPS request to example.com — Blue Team allows once and watches live net.dns, net.tls_sni, and net.close byte counts roll in:

Flip on the AI Judge toggle in the Blue bar (any OpenAI-compatible or local Ollama endpoint) to let an external Blue-Team LLM evaluate the audit timeline while the VM waits frozen.
Measured Numbers & Honest Tradeoffs
Measured on Linux x86_64 (Alpine 3.24.4 / Linux 7.3.4+ aarch64, 128 MiB guest) via unkernel-rs bench:
| Metric | Node.js (v23.11.1 + JSPI) | unkernel-rs (wasmtime 48) |
|---|---|---|
| Runtime footprint | Node.js + unkernel npm pkg | 15 MiB native binary |
| Module load (cached) | 103 ms | 5–6 ms (.cwasm AOT) |
Cold boot → first exec("true") | 379 ms | 254–279 ms |
Peak host RSS (VmHWM) | 231.9 MiB | 72.9 MiB (3.2× less RAM) |
exec("true") round-trip | 3.4 ms | 6.8 ms (5-run avg) |
seq 50000 | sort -r (JIT ON) | 1,340 ms | 2,419 ms (1.75× JIT speedup) |
Two honest limits to keep in mind:
- Emulated CPU throughput: Guest userspace binaries run via
kwemusoftwareaarch64emulation + Cranelift JIT. Great for short agent commands, file sanitizers, and malware triage; heavycargo buildorwebpackruns belong on native Landlock or/dev/kvm. - Host-boundary &
SharedMemorytelemetry: Default audit logs cover everything crossing the host boundary (network + 9P mounts) plus untamperableSharedMemoryVMI process tracking (below), rather than patching guest syscalls. - Fun bonus: Because the Wasm kernel includes namespaces,
overlayfs, andext4, you can even install Docker Engine 29.9 +cruninsideunkernel-rs(--bridge=none --iptables=false+crun --cgroup-manager=disabled) anddocker run --network=host alpineinside WebAssembly — completely rootless.
Update (v0.4.0): Process VMI, Zero-CA TLS 1.3 Decryption & OS Branching
Because the entire guest Linux RAM lives inside wasmtime::SharedMemory, we can push host-side forensics even further without installing a single agent inside the guest:
1. Untamperable Process Monitoring — Even While Frozen
At boot, unkernel-rs inspects wasm_switch_to(prev, next, ...) task pointers directly in SharedMemory and dynamically auto-calibrates Linux struct task_struct offsets (comm, pid, tgid, real_parent) using swapper/0, kthreadd, and kernel worker invariants — zero hardcoded offsets and zero guest code.
- Streams
proc.exec/proc.exitevents and attributes every 9P file op, network connection, and approval card to the exact originating guest process (resolving Linux 9Pkworker/*workqueue TXs back to the userspace caller likecatorwget). vm.active_processes()(and{"procs": true}inserve, plus Inspect Guest in Catch Me If You Can) reads the live guest process table straight out ofSharedMemoryeven while the entire VM is frozen.
2. Forensic HTTPS Decryption (--vmi-tls & --mitm-tls)
For malware/agent forensics, v0.4.0 adds two complementary ways to inspect encrypted HTTPS traffic:
- Zero-CA
SharedMemorykey extraction (--vmi-tls,--tls-keylog): CapturesClientHello.random,ServerHello, and the first encrypted TLS 1.3/1.2 Application Data record, then extracts and AEAD-verifies the live session keys straight from guest RAM — invisible to guestroot, works even with certificate pinning, and writes standard WiresharkSSLKEYLOGFILEentries.- Pass 1 (
client_randomanchor, ~10–25 ms): Matches OpenSSL/BoringSSL (wget,curl, Python, Node,git,apk) whereclient_randomandtraffic_secretsit in the same C struct. - Pass 2 (FindAES) & Pass 3 (parallel high-entropy
traffic_secretscan): Recovers split-heap TLS 1.3CLIENT_TRAFFIC_SECRET_0/SERVER_TRAFFIC_SECRET_0across statically-linked Go (crypto/tls) andrustlstoo — for both AES-128/256-GCM and ChaCha20-Poly1305. - Honest limits: Passive decryption sees raw HTTP/2 frames when clients like Go negotiate
h2(use--tls-keylogwith Wireshark to decode HTTP/2 +gzip), Pass 3 adds ~100–300 ms once per new Go/Rust TLS connection, and mid-stream TLS 1.3KeyUpdaterotations are not yet auto-rescanned.
- Pass 1 (
- Opt-in transparent MITM proxy (
--mitm-tls): Generates an ephemeral per-VM ECDSA Root CA installed only in the disposable guest trust store and bridges TLS via Sans-I/Orustls(forcing readableHTTP/1.1via ALPN across every language and cipher).
# Zero-CA HTTPS decryption straight from SharedMemory + Wireshark keylog
./unkernel-rs exec --sandbox --vmi-tls --tls-keylog ./sslkeylog.txt --audit \
-- wget -qO- https://example.com
3. Copy-on-Write :cow Workspaces & Counterfactual OS Branching
Mount a host repo with -m ./repo:/workspace:cow to stage every guest create, edit, rename, and delete in a pure-Rust in-memory overlay (host directory stays Landlock read-only), then inspect --show-diff, discard, or --commit-cow. Combined with Vm::snapshot() and snap.boot_branch(...) (or snapshot/restore in serve), you can fork an exact ext4 + :cow checkpoint into parallel branches with opposite security policies — e.g., allowing a .env read in Branch A and blocking it in Branch B to compare how an agent reacts.
4. Multi-VM Virtual L2 Switch Lab (unkernel-rs lab) — Inspired by unlab.run
Greg Bell’s unlab.run (gregbell/unlab) showed how fun it is to wire multiple unkernel machines onto a virtual Layer-2 switch in a browser tab. Because unkernel-rs already speaks raw L2 Ethernet frames across wasm_driver_net_*, we added a pure-Rust learning L2 switch (src/switch.rs) and unkernel-rs lab right into the single native binary:
- Parallel multi-VM boot: Boots 2+ isolated Alpine Linux 7.3.4+ VMs in parallel off the shared
.cwasmAOT cache (~372 ms for two nodes, 0.4–1.0 ms inter-VM ping RTT overswitch0). - Real-time chaos & Wireshark PCAPng capture: Cut/reconnect individual node cables (
cut:web→ 100% packet loss,reconnect:web→ 0% packet loss), inject packet loss (drop:client:25) or latency (delay:web:80), inspect the learned MAC table, and record every L2 frame crossingswitch0into a zero-dependency PCAPng file (--pcap lab.pcapng) — with optional per-node NAT uplink, VMI, and TLS inspection.
# Boot 2 air-gapped Alpine VMs on switch0, test cable-cut chaos, and write Wireshark PCAPng
./unkernel-rs lab --node web --node client --pcap ./lab.pcapng \
--run "client:ping -c 2 -W 2 web" \
--run "cut:web" \
--run "client:ping -c 1 -W 1 web" \
--run "reconnect:web" \
--run "client:ping -c 1 -W 2 web" \
--run "macs"
Can unkernel Run k3s? (And Booting unlab-kernel.wasm Directly in unkernel-rs)
It turns out yes — with one key detail:
- Stock
pithings/unkernel0.2.0(unkernel.wasm): Includes all 10 Linux namespaces,overlayfs,ext4,veth, andcgroup2(pids), which is enough for rootlessdockerd --bridge=none --iptables=false+crun --network=host, but omitsbridge,vxlan,nf_tables/nf_conntrack, andcpuset/cpu/memorycgroup controllers. - How
unlab.runruns real multi-nodek3s:gregbell/unlabbuilds and publishes its own customunlab-kernel.wasm(kernel/kw_defconfig+kernel/kw_smp.config) withCONFIG_BRIDGE,CONFIG_BRIDGE_NETFILTER,CONFIG_VETH,CONFIG_VXLAN,CONFIG_NF_TABLES,CONFIG_NETFILTER_XT_TARGET_MASQUERADE,CONFIG_MEMCG,CONFIG_CGROUP_SCHED,CONFIG_CPUSETS,CONFIG_BPF_SYSCALL, andCONFIG_SECCOMP_FILTERenabled — runningk3swithIPTABLES_MODE=nftand Flannel VXLAN across its virtual switch (1024 MiBserver /512 MiBagents). - Drop-in compatible with
unkernel-rs: Becauseunkernel-rsnatively unpacks the exact sameKWP1SMP bundle format, passing--bundle unlab-kernel.wasmbootsunlab’s k3s-ready kernel onwasmtimewith zero code changes (cat /sys/fs/cgroup/cgroup.controllers→cpuset cpu memory pids,bridge,veth,vxlan, and/proc/net/nf_conntrackall active!).
# Boot unLAB's custom k3s-ready Wasm kernel directly on unkernel-rs (zero code changes)
curl -fsSLO https://github.com/gregbell/unlab/releases/download/kernel-5/unlab-kernel.wasm
./unkernel-rs exec --bundle ./unlab-kernel.wasm --rebuild-cache -u root -- \
sh -c 'cat /sys/fs/cgroup/cgroup.controllers && ip link add br0 type bridge && ip link add vx0 type vxlan id 1 && echo k3s-kernel-ready'
(Expect slower control-plane startup than /dev/kvm or Firecracker — k3s is a large Go binary running under emulated aarch64 in Wasm32 with a ~2 GiB guest RAM cap, so unlab’s own k3s test budgets up to 1024 MiB RAM and several minutes for Ready — but as a portable, rootless Kubernetes networking lab it genuinely works.)
Grab the latest release (Linux, macOS, and Windows) on GitHub, copy the quickstart commands, or see what’s next in ideas.md (Git-style persistent .ovl overlay chains, post-run verdict reports, native MCP server, and direct OCI image pulls).
The views and opinions expressed here are my own and do not reflect those of my employer.