# messageport container mesh

- Status: `experiment`
- Track: [browser-delivered vms & container fabrics](https://aifoc.us/labs/browser-delivered-vms/)
- Layer: 10. Browser-Delivered VMs & Container Fabrics
- Updated: 2 December 2026
- Live demo: https://vm-messageport-container-mesh.kinlan-test.workers.dev
- Source: https://github.com/PaulKinlan/vm-messageport-container-mesh

## Inspired by

- [on-device ai needs a trust model](https://aifoc.us/on-device/)
- [my chrome extensions are just prompts](https://aifoc.us/my-chrome-extensions-are-just-prompts/)

## Why this matters

Putting untrusted input processing and sensitive secrets inside one shared Linux container gives any compromised shell command ambient read access to sibling files. This lab boots two completely separate [Unkernel](https://unkernel.dev/) Linux 7.x kernels (`ingest-vm` and `vault-vm`, 96 MiB RAM each) in separate [Dedicated Workers](https://developer.mozilla.org/en-US/docs/Web/API/Worker) with zero external network interfaces, linked only by a policy-mediated [`MessageChannel`](https://html.spec.whatwg.org/multipage/web-messaging.html#message-ports)—and includes an **Unfiltered Naive Relay** switch to test what breaks when channel policy enforcement is removed.

## What this opens up

Zero-server multi-container pipelines directly in a browser tab using standard POSIX tools (`sh`, `awk`, `sha256sum`): Container A pipes untrusted CSV files from `/work` through `/run/kw/bin/port-call compute_totals`, Container B computes aggregates against private tables in `/vault` without exposing `/vault/canary-secret.txt`, and one click closes both ports with `410 PORT_REVOKED`.

## How the tests work

1. Click **1. Boot Both Containers** to start `ingest-vm` (`/work`) and `vault-vm` (`/vault`) as two independent Linux 7.x WebAssembly kernels and verify distinct hostnames, PIDs, mount trees, and loopback-only networking.
2. Click **2. Run Cross-VM Pipe** to execute `sh -c "cat /work/raw-orders.csv | port-call compute_totals"` inside Container A and observe Container B run real Linux `awk` and `sha256sum` against `/vault/pricing.json`.
3. Click **3. Fire All 3 Attacks** in **Policy-Mediated Broker** mode to verify `ENOENT` on `/vault`, `403 POLICY_DENIED` on `port-call read_secret`, and zero-network failure on `wget`—then flip the toggle to **Unfiltered Naive Relay** and re-run to observe live canary exfiltration.
4. Click **4A. Revoke Port** to close both `MessagePort` ends immediately (`410 PORT_REVOKED`), reconnect a fresh `MessageChannel` without rebooting Linux, and click **4B. Run Benchmark** to compare cloned JSON against zero-copy transferable `ArrayBuffer` transfers (`byteLength === 0` detachment proof).


## Hypothesis

- **Claim:** Splitting untrusted ingestion and private vault computation across two zero-network browser Linux 7.x VMs prevents cross-container secret exfiltration ONLY when the connecting `MessagePort` is mediated by an explicit operation allowlist, argument path guard, and canary egress filter.
- **Confirms it:** Direct `cat /vault/canary-secret.txt` inside Container A returns kernel `ENOENT`, `wget` fails with loopback-only networking, `port-call read_secret` returns `403 POLICY_DENIED`, `cat /work/raw-orders.csv | port-call compute_totals` returns aggregated totals from Container B's `awk`/`sha256sum`, and `port.close()` cuts off traffic with `410 PORT_REVOKED`.
- **Bounds or disproves it:** Flipping the broker mode to **Unfiltered Naive Relay** allows `port-call read_secret /vault/canary-secret.txt` from Container A to exfiltrate `CANARY_VAULT_SECRET_9f83c1a4_DO_NOT_EXFILTRATE` across the `MessagePort`, proving transport separation without frame policy enforcement is insufficient.


## Under the hood

[MessagePort Container Mesh](https://vm-messageport-container-mesh.kinlan-test.workers.dev) ([GitHub](https://github.com/PaulKinlan/vm-messageport-container-mesh)) instantiates `public/container-worker.js` twice in separate [Dedicated Workers](https://developer.mozilla.org/en-US/docs/Web/API/Worker), booting two independent [Unkernel](https://unkernel.dev/) Linux 7.x kernels (`memoryMiB: 96` each, zero external network devices):

- **Container A (`ingest-vm`)** mounts `MemoryFs` at `/work` (`raw-orders.csv`, `README.md`) and registers `/run/kw/bin/port-call` and `/run/kw/bin/port-ping` host commands that forward stdin and arguments as structured RPC frames over its `MessagePort`.
- **Container B (`vault-vm`)** mounts private `MemoryFs` at `/vault` (`pricing.json`, `canary-secret.txt`), receives validated RPC frames on its `MessagePort`, executes real Linux `/bin/awk` and `/bin/sha256sum` inside the guest against `/vault/pricing.json`, and returns only aggregated totals and payload digests.
- **Port Broker (`public/lib/port-broker.js`)** mediates the `MessageChannel` pair between both workers, enforcing an explicit operation allowlist (`compute_totals`, `hash_payload`, `health`), blocking traversal or `/vault` arguments (`403`), scanning egress responses for canary strings, recording every frame in the wire audit log, and closing both ports immediately on revocation (`410 PORT_REVOKED`). Switching the broker to **Unfiltered Naive Relay** bypasses policy validation so readers can test the falsification signal directly against `canary-secret.txt`.


## Key terms & further reading

- [Unkernel (Linux 7.x on WebAssembly)](https://unkernel.dev/) — An aarch64 Linux 7.x kernel compiled to WebAssembly that runs standard POSIX userland binaries (`sh`, `awk`, `sha256sum`) inside a browser Dedicated Worker with zero server compute.
- [WebAssembly JSPI (WebAssembly.Suspending)](https://github.com/WebAssembly/js-promise-integration) — JavaScript Promise Integration allows synchronous WebAssembly kernel execution to suspend cleanly on asynchronous host I/O such as 9p virtual filesystems and host command bridges.
- [MessageChannel & MessagePort](https://html.spec.whatwg.org/multipage/web-messaging.html#message-ports) — A transferable pair of capability ports defined by the HTML Standard that establish a private point-to-point channel between two Dedicated Workers and terminate immediately on `port.close()`.
- [Transferable ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Transferable_objects) — Passing an `ArrayBuffer` in the `postMessage(msg, [buf])` transfer list moves ownership across workers without copying bytes, detaching the sender buffer (`byteLength === 0`).
- [Unkernel Host Commands (/run/kw/bin/*)](https://github.com/pithings/unkernel) — Virtual binaries mounted on the guest `$PATH` that bridge Linux stdin, stdout, stderr, and argv over vsock into host JavaScript handlers.
- [Dedicated Worker Isolation](https://developer.mozilla.org/en-US/docs/Web/API/Worker) — Each Dedicated Worker runs in an isolated JavaScript realm with its own linear `WebAssembly.Memory` and `MemoryFs` tree, preventing Container A from referencing Container B's `/vault`.

## Open questions to iterate on

- How does two-VM memory overhead (~192 MiB total for two 96 MiB kernels) scale on constrained mobile devices if a workflow needs three or four isolated container stages?
- Could streaming `ReadableStream` transfers over `MessagePort` replace buffered `ArrayBuffer` frames for multi-megabyte Linux pipeline payloads?

## Iteration log

- **2026-12-02:** Initial deployment: two real Unkernel 0.3.0-261202-b033dc7 Linux 7.x Dedicated Workers (`ingest-vm` and `vault-vm`), pure `port-broker.js` policy gate with switchable Unfiltered Naive Relay mode, live `port.close()` revocation, transferable `ArrayBuffer` benchmark, and 12 automated tests including two-VM Node integration.

## Primitives tested

- `Unkernel Linux 7.x`
- `WebAssembly JSPI`
- `Dedicated Worker`
- `MessageChannel`
- `Transferable ArrayBuffer`
- `MemoryFs (9p)`

## Connected labs in other tracks

- [slice capability mesh](https://aifoc.us/labs/browser-containment/slice-capability-mesh/) — Applies revocable capability boundaries and falsification probes to OPFS storage slices.
- [agent containment lab](https://aifoc.us/labs/browser-containment/agent-containment-lab/) — Tests iframe origin isolation and capability mediation for untrusted browser workloads.

---
Canonical: https://aifoc.us/labs/browser-delivered-vms/vm-messageport-container-mesh/
