# agent containment lab

- 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://agent-containment-lab.kinlan-test.workers.dev
- Source: https://github.com/PaulKinlan/agent-containment-lab

## Inspired by

- [the browser is the sandbox](https://aifoc.us/the-browser-is-the-sandbox/)
- [shipping a prompt](https://aifoc.us/shipping-a-prompt/)
- [on-device ai needs a trust model](https://aifoc.us/on-device/)

## Hypothesis

- **Claim:** Opaque sandbox iframes paired with HTTP egress locks (`Connection-Allowlist` / strict CSP) or explicit taint tracking block exfiltration from untrusted text, whereas standard Same-Origin Policy and `allow-scripts allow-same-origin` iframes fail completely.
- **Confirms it:** All simulated exfiltration channels (`fetch`, `sendBeacon`, `<img>`, CSS `url()`, WebRTC ICE, 302 redirects) record zero hits on the Durable Object `CanarySession` under strict tiers.
- **Falsifies or bounds it:** A DNS prefetch, WebRTC candidate, CSS fetch, or misconfigured sandbox combination delivers a canary token to the collector despite an active containment tier.

> **Why this exists:** The browser Same-Origin Policy keeps different websites separate, not untrusted text pulled into your own page or agent loop. When injected text runs script or triggers network fetches in a first-party context, standard origin isolation stops nothing. This lab benchmarks which concrete browser boundaries (sandboxed iframes, strict CSP, Web Workers, Chrome `Connection-Allowlist` headers, Proxy/WeakSet taint tracking, and zero-egress enclaves) actually halt data exfiltration against a real Durable Object canary collector.


## What this lab tests

When untrusted web text enters an agent loop running in the browser, Same-Origin Policy does not block first-party exfiltration channels such as `fetch()`, `navigator.sendBeacon()`, `<img src>`, stylesheets, or WebSockets. Combining `allow-scripts` and `allow-same-origin` on a same-origin [`<iframe sandbox>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/iframe#sandbox) lets embedded scripts inspect `parent.document` and `parent.localStorage`.

[Agent Containment Lab](https://agent-containment-lab.kinlan-test.workers.dev) ([GitHub](https://github.com/PaulKinlan/agent-containment-lab)) executes live probes (including 302 redirects and WebRTC ICE candidates) across 7 containment tiers backed by a Cloudflare SQLite Durable Object collector (`CanarySession`), adds a dedicated WICG [`Connection-Allowlist`](https://chromestatus.com/feature/5175745573945344) policy builder (`()` empty list, `(response-origin)`, `URLPattern`, `Connection-Allowlist-Report-Only`, `redirects=allow`, [`ReportingObserver`](https://wicg.github.io/connection-allowlists)), and pairs it with a `WeakSet` + `Proxy` taint engine and a dual-locked enclave.


## Open questions to iterate on

- Which indirect exfiltration paths (navigation links, form GET submits, prefetch hints) still bypass `Connection-Allowlist` in current builds?
- Can declassification rules in `WeakSet`/`Proxy` taint tracking stay ergonomic without blocking legitimate user-triggered exports?

## Iteration log

- **2026-12-01:** Deployed 7-tier containment suite with Durable Object `CanarySession`, WICG `Connection-Allowlist` builder, and top-of-page code blueprint.
- **2026-12-01:** Hardened host CSP (`frame-ancestors` + `no-cache` static routing), moved interactive containment tabs above the setup blueprint for 700px embeds, and added pure-DOM syntax highlighting with 20 passing checks.

## Primitives tested

- `<iframe sandbox>`
- `CSP Level 3`
- `Connection-Allowlist`
- `Reporting-Endpoints`
- `ReportingObserver`
- `Worker`
- `WeakSet`
- `Proxy`
- `Durable Object SQLite`

## Connected labs in other tracks

- [slice capability mesh](https://aifoc.us/labs/browser-containment/slice-capability-mesh/) — Pairs network egress containment with OPFS folder-level storage isolation.
- [web + ai spec polyfill testbed](https://aifoc.us/labs/hypermedia-and-islands/spec-polyfill-browser/) — Benchmarks `Connection-Allowlist` alongside WebMCP and `<web-island>` assertions.

---
Canonical: https://aifoc.us/labs/browser-containment/agent-containment-lab/
