# slice capability mesh

- Status: `experiment`
- Track: [browser containment & sandbox boundaries](https://aifoc.us/labs/browser-containment/)
- Layer: 1. Execution Containment & Browser Security
- Updated: 1 December 2026
- Live demo: https://slice-capability-mesh.kinlan-test.workers.dev
- Source: https://github.com/PaulKinlan/slice-capability-mesh

## Inspired by

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

## Hypothesis

- **Claim:** A Service Worker `/cap/<token>/<path>` broker keeps storage scoped per task ONLY when untrusted consumers are isolated in opaque origins and OPFS blobs are encrypted per slice behind salted hashed names.
- **Confirms it:** Opaque `<iframe sandbox="allow-scripts">` throws `SecurityError` on `navigator.storage.getDirectory()`, page disk enumeration shows only `blob-<hash>.enc` envelopes, and cross-slice decryption rejects with `OperationError`.
- **Falsifies or bounds it:** Any same-origin script can reconstruct slice contents or enumerate plaintext directory names directly from `navigator.storage.getDirectory()` without holding the non-extractable slice key.

> **Why this exists:** Granting scripts or plugins access to browser storage normally exposes an entire origin's `localStorage` or `IndexedDB`, making folder-level isolation hard to enforce. This lab mints narrow, revocable `/cap/<token>/...` Service Worker URLs scoped to specific OPFS subdirectories without leaking sibling folders.


## What this lab tests

Granting a page or embedded script ambient origin storage (`localStorage`, `IndexedDB`, or full storage roots) exposes unrelated secrets across tasks. How do native browser primitives enforce per-task least-privilege file access instead?

[Slice Capability Mesh](https://slice-capability-mesh.kinlan-test.workers.dev) ([GitHub](https://github.com/PaulKinlan/slice-capability-mesh)) seeds sample directories inside [Origin Private File System (OPFS)](https://developer.mozilla.org/en-US/docs/Web/API/File_System_API/Origin_private_file_system) (`private/`, `workspace/`, `shared/`), mints short-lived capability tokens tied to `/cap/<token>/<path>` routes, and enforces directory containment, read-only vs. read-append permissions, path-traversal rejection (`../`), max read counts, and immediate revocation inside a [Service Worker](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API) `FetchEvent` broker.


## Open questions to iterate on

- What happens to UX and throughput when large binary files stream through AES-GCM chunk encryption inside `sw.js`?
- When will browsers ship Service-Worker-private storage buckets (`StorageBucket`) so page scripts never share an OPFS directory tree with the broker?

## Iteration log

- **2026-12-01:** Initial deployment: OPFS directories + Service Worker `FetchEvent` capability URLs with traversal and write-escalation guards.
- **2026-12-01:** Added per-slice non-extractable AES-256-GCM keys, salted SHA-256 opaque blob IDs (`opfs://vault/`), `<iframe sandbox="allow-scripts">` attack probe, and CSP-safe syntax highlighting.
- **2026-12-01:** Moved the interactive OPFS vault workbench above the setup blueprint for 700px embeds, updated setup snippets to match AES-256-GCM vault decryption, and routed all static CSS/JS assets through the Worker with `no-cache` headers (29 passing checks).

## Primitives tested

- `OPFS`
- `Service Worker FetchEvent`
- `ReadableStream`
- `URL Capability Tokens`

## Connected labs in other tracks

- [agent containment lab](https://aifoc.us/labs/browser-containment/agent-containment-lab/) — Tests why omitting `allow-same-origin` on sandbox iframes is required for origin isolation.
- [malleable worker plugin shell](https://aifoc.us/labs/agent-meshes/malleable-worker-shell/) — Applies similar narrow capability checks to worker UI slots.

---
Canonical: https://aifoc.us/labs/browser-containment/slice-capability-mesh/
