Metadata-Version: 2.4
Name: unkernel-rs
Version: 0.7.0
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Rust
Classifier: Topic :: Security
Classifier: Topic :: System :: Emulators
Summary: Embeddable Linux 7.x micro-VM sandbox on WebAssembly (Wasmtime) — zero Docker, zero KVM, zero root, with CoW branching, Freeze-on-Ask, and Level-3 VMI TLS inspection
Keywords: wasm,wasmtime,linux,sandbox,unkernel,ai-agents,vmi
Author: Nils Jannasch
License: MIT OR Apache-2.0
Requires-Python: >=3.9
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Homepage, https://github.com/NJannasch/unkernel-rs
Project-URL: Issues, https://github.com/NJannasch/unkernel-rs/issues
Project-URL: Repository, https://github.com/NJannasch/unkernel-rs

# `unkernel-rs` for Python

Embeddable **Linux 7.x micro-VM sandbox** running inside WebAssembly (`wasmtime`) — **zero Docker, zero KVM, zero root, zero Node.js**.

Powered by [`unkernel-rs`](https://github.com/NJannasch/unkernel-rs) and [`pithings/unkernel`](https://github.com/pithings/unkernel).

## Install

```bash
pip install unkernel-rs
```

On first boot, `unkernel-rs` downloads and SHA-256-verifies the pinned `unkernel.wasm` + `alpine.erofs` (~26 MB) into your local cache and AOT-compiles a `.cwasm` image for ~1s warm boots.

## Quickstart

### 1. Disposable Air-Gapped Linux VM

```python
import unkernel_rs

with unkernel_rs.Vm() as vm:
    res = vm.exec(["uname", "-a"])
    print(res.stdout_text)
    print(vm.active_processes())  # Level-3 SharedMemory VMI
```

### 2. Port Forwarding, SSH & Remote Desktop (VNC)

Forward any host TCP port into the guest with `port_forwards=["127.0.0.1:2222:22"]` — preview web servers (`http://localhost:8000`), SSH straight into the Wasm Linux VM with real OpenSSH, or even launch a full X11 + Fluxbox desktop over VNC:

```python
import unkernel_rs

with unkernel_rs.Vm(net=True, port_forwards=["127.0.0.1:2222:22"]) as vm:
    vm.shell("apk add --no-cache dropbear && mkdir -p /etc/dropbear && dropbear -R -p 22", user="root")
    input("SSH ready on 127.0.0.1:2222 — press Enter to stop...")
```

- **SSH example:** [`examples/ssh_into_vm.py`](examples/ssh_into_vm.py) (automatic ED25519 key setup, ~345 ms SSH round-trip, ~33 ms HTTP round-trip).
- **Remote Desktop (VNC) example:** [`examples/desktop_vnc.py`](examples/desktop_vnc.py) (Xvfb + Fluxbox + `xterm` + `x11vnc` on `vnc://127.0.0.1:5900`, persisted on a 4 GiB sparse `ext4` disk so subsequent boots take ~3–5s).

### 3. Copy-on-Write Workspace & Counterfactual Branching

```python
import unkernel_rs

with unkernel_rs.Vm(mounts=["./repo:/work:cow"]) as vm:
    vm.shell("echo base > /work/state.txt")
    snap = vm.snapshot()

    with snap.branch() as branch_a, snap.branch() as branch_b:
        branch_a.shell("echo fix_a >> /work/state.txt")
        branch_b.shell("echo fix_b >> /work/state.txt")

        print(branch_a.workspace_diff("/work"))
        branch_a.commit_workspace("/work")  # commit winner, discard loser
```

### 4. Zero-MITM Level-3 VMI TLS Inspection & Audit Stream

```python
import unkernel_rs

events = []
with unkernel_rs.Vm(
    net=True,
    allow_hosts=["example.com"],
    vmi_tls=True,
    on_audit=events.append,
) as vm:
    res = vm.shell("wget -qO- https://example.com | head -n 1")
    print(res.stdout_text)

for ev in events:
    if ev["event"] == "net.tls_decrypted":
        print(ev["direction"], ev.get("http_summary"), ev["proc"])
```

### 5. Freeze-on-Ask Policy Callback

```python
import unkernel_rs

def approve(req: dict) -> str:
    # Entire guest kernel + monotonic clock are frozen while this runs!
    return "allow_once" if "example.com" in req["target"] else "deny_once"

with unkernel_rs.Vm(
    net=True,
    allow_hosts=["example.com"],
    ask_net=True,
    freeze_on_ask=True,
    on_approval=approve,
) as vm:
    res = vm.shell("wget -qO- https://example.com | head -n 1")
```

### 6. Built-In MCP Server (`unkernel-mcp`)

Installing `unkernel-rs` also installs the `unkernel-mcp` stdio JSON-RPC 2.0 server for Claude Desktop, Claude Code, Cursor, Antigravity, and OpenCode — exposing `vm_exec`, `vm_snapshot`, `vm_branch_exec`, `vm_diff`, `vm_read_file`, `vm_commit`, `vm_discard`, and `vm_inspect`:

```json
{
  "mcpServers": {
    "unkernel": {
      "command": "uvx",
      "args": ["--from", "unkernel-rs", "unkernel-mcp", "--mount", ".:/work:cow"]
    }
  }
}
```

## License

Dual-licensed under **MIT OR Apache-2.0**. Upstream `unkernel` Linux kernel images (`GPL-2.0-only`) are fetched at runtime and never bundled in this wheel.

