Skip to main content

Booting Linux Inside WebAssembly: Rootless 73 MiB Sandboxes with Freeze-on-Ask Auditing

· 10 min read

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 wasmtime on 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 .env access from outside the guest kernel. (Looking for the newer 3-line Python pip install unkernel-rs walkthrough and v0.9.0–v0.10.0 features? 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.

Dimensionnono / LandlockDockerKVM / Firecrackerunkernel-rs
Root daemon / KVM / Hyper-VNoRoot daemon (or WSL2/VM)Yes (/dev/kvm)No (100% rootless)
Separate Linux kernelNoNoYesYes (Linux 7.3.4+ in Wasm)
Fake root + apk/aptNoYesYesYes
Host RAM (idle VM)~0 MiB~20–50 MiB + daemon~5–30 MiB + guest72.9 MiB
Cold boot → command< 5 ms~150–400 ms~125–300 ms254–279 ms
Guest CPU speedNativeNativeNear-nativeEmulated aarch64 + JIT
Linux + macOS + WindowsLinux onlyNeeds Linux VM on Mac/WinLinux KVM onlyYes (single native binary)

Three independent isolation rings stack together:

Three isolation rings of unkernel-rs: Outer Linux Landlock ABI v4 sandbox, Rust and Wasmtime host with Audit Monitor and PauseController, and inner Guest Linux 7.3.4+ kernel

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 SYN gating (--ask-net): Holds outbound connections before any host TcpStream opens. Denying injects a TCP RST with zero packets leaving your machine; allowing still logs DNS, TLS ClientHello SNI (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 — including O_RDWR, truncate, and mv .env benign.txt rename bypasses.
  • Whole-VM freeze (--freeze-on-ask): Uses wasmtime epoch 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:

Catch Me If You Can WebUI mid-attack: Red Team shell frozen on cat /workspace/.env while Blue Team receives a live FS_SENSITIVE_READ approval card with Allow and Deny buttons

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:

Catch Me If You Can WebUI audit timeline showing denied .env access, blocked 192.168.1.1 LAN SSRF, and live example.com TLS SNI and byte-count telemetry

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:

MetricNode.js (v23.11.1 + JSPI)unkernel-rs (wasmtime 48)
Runtime footprintNode.js + unkernel npm pkg15 MiB native binary
Module load (cached)103 ms5–6 ms (.cwasm AOT)
Cold boot → first exec("true")379 ms254–279 ms
Peak host RSS (VmHWM)231.9 MiB72.9 MiB (3.2× less RAM)
exec("true") round-trip3.4 ms6.8 ms (5-run avg)
seq 50000 | sort -r (JIT ON)1,340 ms2,419 ms (1.75× JIT speedup)

Two honest limits to keep in mind:

  • Emulated CPU throughput: Guest userspace binaries run via kwemu software aarch64 emulation + Cranelift JIT. Great for short agent commands, file sanitizers, and malware triage; heavy cargo build or webpack runs belong on native Landlock or /dev/kvm.
  • Host-boundary & SharedMemory telemetry: Default audit logs cover everything crossing the host boundary (network + 9P mounts) plus untamperable SharedMemory VMI process tracking (below), rather than patching guest syscalls.
  • Fun bonus: Because the Wasm kernel includes namespaces, overlayfs, and ext4, you can even install Docker Engine 29.9 + crun inside unkernel-rs (--bridge=none --iptables=false + crun --cgroup-manager=disabled) and docker run --network=host alpine inside 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.exit events and attributes every 9P file op, network connection, and approval card to the exact originating guest process (resolving Linux 9P kworker/* workqueue TXs back to the userspace caller like cat or wget).
  • vm.active_processes() (and {"procs": true} in serve, plus Inspect Guest in Catch Me If You Can) reads the live guest process table straight out of SharedMemory even 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 SharedMemory key extraction (--vmi-tls, --tls-keylog): Captures ClientHello.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 guest root, works even with certificate pinning, and writes standard Wireshark SSLKEYLOGFILE entries.
    • Pass 1 (client_random anchor, ~10–25 ms): Matches OpenSSL/BoringSSL (wget, curl, Python, Node, git, apk) where client_random and traffic_secret sit in the same C struct.
    • Pass 2 (FindAES) & Pass 3 (parallel high-entropy traffic_secret scan): Recovers split-heap TLS 1.3 CLIENT_TRAFFIC_SECRET_0 / SERVER_TRAFFIC_SECRET_0 across statically-linked Go (crypto/tls) and rustls too — 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-keylog with Wireshark to decode HTTP/2 + gzip), Pass 3 adds ~100–300 ms once per new Go/Rust TLS connection, and mid-stream TLS 1.3 KeyUpdate rotations are not yet auto-rescanned.
  • 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/O rustls (forcing readable HTTP/1.1 via 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 .cwasm AOT cache (~372 ms for two nodes, 0.4–1.0 ms inter-VM ping RTT over switch0).
  • 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 crossing switch0 into 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/unkernel 0.2.0 (unkernel.wasm): Includes all 10 Linux namespaces, overlayfs, ext4, veth, and cgroup2 (pids), which is enough for rootless dockerd --bridge=none --iptables=false + crun --network=host, but omits bridge, vxlan, nf_tables/nf_conntrack, and cpuset/cpu/memory cgroup controllers.
  • How unlab.run runs real multi-node k3s: gregbell/unlab builds and publishes its own custom unlab-kernel.wasm (kernel/kw_defconfig + kernel/kw_smp.config) with CONFIG_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, and CONFIG_SECCOMP_FILTER enabled — running k3s with IPTABLES_MODE=nft and Flannel VXLAN across its virtual switch (1024 MiB server / 512 MiB agents).
  • Drop-in compatible with unkernel-rs: Because unkernel-rs natively unpacks the exact same KWP1 SMP bundle format, passing --bundle unlab-kernel.wasm boots unlab’s k3s-ready kernel on wasmtime with zero code changes (cat /sys/fs/cgroup/cgroup.controllers → cpuset cpu memory pids, bridge, veth, vxlan, and /proc/net/nf_conntrack all 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.