unkernel-rs
Embeddable Linux 7.x micro-VMs for Python, Rust, CLI, and AI Agents (MCP) — hosting pithings/unkernel directly on wasmtime across Linux, macOS, and Windows with zero Docker, zero KVM, zero WSL2, zero Node.js, and zero root.
Boot a disposable Linux VM in ~185 ms (~51 MiB RAM), mount your repo in draft mode (:cow), pull Docker images without a daemon, wrap untrusted MCP servers, or freeze the entire guest OS before .env leaves disk.
Install
# Python (Linux x86_64/aarch64, macOS arm64, Windows x64 — Python 3.9+)
# Rust CLI & library
Why unkernel-rs?
- Draft-mode workspaces (
:cow): Mount host folders in an in-memory Copy-on-Write overlay — review diffs, commit the good edits, or discard everything. - Zero-daemon Docker / OCI images (
--image): Pull and runalpine:3.21or otherlinux/arm64images over HTTPS with no Docker daemon installed. - Sandbox untrusted MCP servers (
wrap-mcp): Lock third-partynpx/uvxstdio MCP servers inside an air-gapped or domain-allowlisted micro-VM. - Freeze-on-Ask & native
--sinkhole: Pause the entire guest kernel + clock mid-syscall for approval, or trap all HTTP/HTTPS locally with200 OKand zero egress. - Zero-MITM HTTPS & Process VMI (
--vmi-tls): Inspect live guest PIDs and decrypt TLS 1.3 straight fromSharedMemory— invisible to guestroot, no CA needed. - Sub-ms warm pools (
VmPool): Snapshot once, then acquire pre-warmed independent branches in< 1 ms.
Examples
Python (pip install unkernel-rs)
# 1. Air-gapped Linux VM with safe draft-mode (:cow) folder mount
=
# ./repo untouched until commit!
# 2. Zero-daemon OCI image + sub-ms warm pool + local 200-OK sinkhole
=
=
# < 1 ms from warm pool, replenished in background
See bindings/python/README.md for SSH/VNC port forwarding, portable .uksnap snapshots, zero-MITM --vmi-tls, and Freeze-on-Ask callbacks.
Rust (cargo add unkernel-rs)
use Arc;
use ;
CLI & MCP (unkernel-rs)
# Run any Docker/OCI image without Docker
# Trap outbound HTTP/HTTPS locally (200 OK, zero egress, full decrypted payload audit)
# Detonate & score an untrusted npm/pip package (exits 2 on suspicious behavior)
Sandbox any third-party MCP server (wrap-mcp) or expose a sandboxed Linux VM as an MCP server (mcp) in Claude Desktop, Claude Code, Cursor, Antigravity, or OpenCode:
Honest Tradeoffs
- Where it shines: Unprivileged, zero-KVM, zero-Docker, cross-OS Linux sandboxing inside nested VMs, CI runners, Kubernetes pods, or developer laptops for AI agent tools, MCP servers, untrusted scripts, and security labs.
- Where other tools win: Guest userspace runs via emulated
aarch64+ Cranelift JIT. Heavycargo build,webpack, or video encoding jobs belong on/dev/kvmmicroVMs (Firecracker,libkrun) or native OS sandboxing (nono/ Landlock). - Upstream ABI & scope: Pinned and SHA-256-verified to
unkernel v0.3.0-261130-3ef745b(Alpine 3.24.4 / Linux 7.3.4+). Headless by design (no GPU/audio/evdev; useport_forwards+ Xvfb/x11vnc if you want a remote desktop).
Deep Dives
Upstream unkernel relies on V8/Node's experimental WebAssembly JSPI (WebAssembly.Suspending) to suspend/resume Linux kernel task stacks during wasm_switch_to.
unkernel-rs avoids JSPI, Asyncify, and unstable stack-switching proposals by unpacking the SMP kernel delta (unkernel.kernel.smp.kwpatch, src/kwpatch.rs) bundled inside unkernel.wasm:
env.memoryisshared(flags=0x3) — maps directly to stablewasmtime::SharedMemory.- 0 active data segments, 38 passive data segments, initialized once atomically via
__wasm_init_memory/__wasm_init_memory_flag— instantiating additionalwasmtime::Instances on the sameSharedMemorynever overwrites kernel.data. - Per-CPU mutable globals (
__stack_pointer,__tls_base,current,kw_irq_flags,kw_irq_word) are automatically re-exported before AOT compilation and saved/restored acrosswasm_switch_toviampsc::sync_channel(1). - Process-wide
Engine/Module/initrdcache eliminates.cwasmreload overhead (0 mswarmmodule_load_msacross repeated boots and branches).
+-----------------------------------------------------------------------+
| Outer OS Sandbox (Linux Landlock ABI v4 + PR_SET_NO_NEW_PRIVS) |
| - Host FS restricted strictly to explicit --mount dirs (or none) |
| - Host TCP bind/connect blocked on Landlock ABI v4+ |
| |
| +-----------------------------------------------------------------+ |
| | Rust + Wasmtime Host (StoreLimits + Epoch Timeout) | |
| | | |
| | SharedMemory (128 MiB guest RAM) <-- shared by all tasks | |
| | InstancePre<TaskStore> <-- pre-linked once | |
| | | |
| | [kthread 0] <-- 5 globals + token via sync_channel(1) --> | |
| | [kthread 1] (single-CPU cooperative, wasm_cpu_count=1) | |
| | | |
| | Drivers: Block RO (.erofs) | Vsock + IRQ | Cranelift JIT | |
| | Services: kwtty (port 1022) | 9P2000.L (port 564) | |
| +-----------------------------------------------------------------+ |
+-----------------------------------------------------------------------+
# Download & SHA-256 verify pinned unkernel.wasm + alpine.erofs and build .cwasm cache
# Air-gapped, Landlock-sandboxed Linux command
# Stage edits in Copy-on-Write (:cow) mode and print diff without mutating host files
# Zero-MITM HTTPS inspection via SharedMemory key extraction + Wireshark SSLKEYLOGFILE
# Transparent ephemeral-CA MITM proxy (--mitm-tls) or local 200-OK trap (--sinkhole)
# Persistent sparse 4 GiB ext4 overlay disk + immutable COW snapshot reuse
# Boot Debian 13 or any OCI/Docker image (--image)
# Hard epoch timeout, interactive PTY shell, or multi-VM virtual L2 switch lab (--pcap)
Start serve with --audit and any --ask-* flags:
| Direction | Message Example | Purpose |
|---|---|---|
| Host → Controller | {"event":"proc.exec","pid":42,"ppid":41,"comm":"curl",...} |
Untamperable Level-3 VMI guest process lifecycle from SharedMemory |
| Host → Controller | {"event":"approval.required","approval_id":1,"kind":"fs_sensitive_read","target":"/workspace/.env","proc":{...}} |
Operation paused awaiting judgment (with originating guest process) |
| Host → Controller | {"event":"vm.paused","ts_ms":...,"reason":"approval #1: /workspace/.env"} |
Whole VM frozen via epoch interruption |
| Host → Controller | {"event":"net.tls_sni","ip":"...","port":443,"sni":"registry.npmjs.org","proc":{...}} |
Extracted TLS ClientHello SNI |
| Host → Controller | {"event":"net.tls_decrypted","ip":"...","port":443,"method":"vmi","direction":"tx","http_summary":"GET /...","preview":"..."} |
Decrypted HTTPS payload (--vmi-tls, --mitm-tls, or --sinkhole) |
| Host → Controller | {"event":"net.http","ip":"...","port":80,"method":"POST","path":"/exfil","host":"...","proc":{...}} |
Extracted HTTP request line |
| Controller → Host | {"id":"a1","approve":1,"decision":"deny_once"} |
Resolve approval (allow_once | allow_always | deny_once | deny_always) |
| Controller → Host | {"id":"p1","pause":true} / {"id":"p2","resume":true} |
Manually freeze / resume entire guest VM & clock |
| Controller → Host | {"id":"ps1","procs":true} |
List live guest Linux processes via VMI (works even while frozen) |
| Controller → Host | {"id":"d1","diff":"/workspace"} / {"id":"x1","discard":"/workspace"} / {"id":"c1","commit":"/workspace"} |
Inspect, roll back, or commit staged :cow workspace changes |
| Controller → Host | {"id":"s1","snapshot":"cp1"} / {"id":"r1","restore":"cp1"} |
Capture a named Tier-A disk+workspace snapshot or restore from it |
| Controller → Host | {"id":1,"cmd":"npm test","cwd":"/workspace"} / {"shutdown":true} |
Execute command or cleanly flush disks and power off |
Try the zero-dependency Red-Team vs. Blue-Team browser demo (examples/catch_me_if_you_can.rs):
# Local solo split-screen demo (http://127.0.0.1:8787/)
# Two-player LAN mode (prints separate /red and token-protected /blue URLs)
/(Split View): Left pane runs a live guest Linux shell seeded with decoy canary secrets (/workspace/.env,.npmrc,.ssh/id_ed25519); right pane shows the untamperable host SOC monitor with real-time SSE audit telemetry, whole-VM Freeze / Resume, forensic guest inspection, and Allow / Deny approval cards.- Optional AI Blue-Team Auto-Judge: Toggle AI Judge (or pass
--ai-endpoint+--ai-model, e.g., local Ollamahttp://127.0.0.1:11434/v1/chat/completions) to let an external LLM evaluate the audit timeline while the VM stays frozen.
Reproduce locally with unkernel-rs bench (Linux x86_64 host, Alpine 3.24.4 / Linux 7.3.4+ aarch64, 128 MiB guest):
| Metric | Node.js (v23.11.1 + JSPI) |
unkernel-rs (wasmtime 48) |
|---|---|---|
| Runtime footprint | Node.js + unkernel npm pkg |
15 MiB native binary (5.9 MiB Python wheel) |
| Module load / compile | 103 ms (createKernel) |
~2.2 s cold AOT → 5–6 ms .cwasm → 0 ms in-process cache |
Warm boot → first exec("true") |
379 ms | ~185 ms (64 MiB minimal) / 254–315 ms (Alpine) |
Warm VmPool::acquire() |
— | < 1 ms (background-replenished branch pool) |
| Peak host RSS (single VM) | 231.9 MiB | 51–73 MiB (3.2× less RAM) |
seq 50000 | sort -r (JIT ON / OFF) |
1,340 ms (V8) | 2,419 ms / 4,228 ms (1.75× Cranelift JIT speedup) |
Also verified via --bundle with Linux x86_64 (@JeremySu0818), Linux + OpenZFS, FreeBSD 16.0-CURRENT, and OpenBSD 8.0-current (tsirysndr/unkernel-assets).
Unit and live Linux VM integration tests cover kwpatch SHA-256 identity, exec / wrap-mcp stdio pipes, 9P2000.L :ro/:rw/:cow mounts + symlink-escape blocking + diff/discard/commit, sparse ext4 disks + Tier-A OS branching + < 1 ms VmPool, zero-daemon OCI image import (alpine:3.21), native 200-OK --sinkhole + virtual --time-warp, Level-3 VMI process attribution + frozen-VM inspection, zero-MITM --vmi-tls + --mitm-tls, SSRF-protected NAT + --allow-host, Cranelift JIT, epoch timeouts, Linux Landlock ABI v4, and concurrent NDJSON serve.
Licensing
unkernel-rs is dual-licensed under MIT (LICENSE-MIT) or Apache-2.0 (LICENSE-APACHE).
Runtime artifacts downloaded and cached on first use remain under their respective upstream licenses:
unkernel.wasm(Linux 7.x kernel) — GPL-2.0-only (pithings/unkernel).- Distro / OCI images — licenses of their included distribution packages.