Agent Containment Lab

Problem & Hypothesis: Same-Origin Policy separates origins, not untrusted text processed inside first-party agent loops. Opaque sandbox iframes paired with HTTP egress locks (Connection-Allowlist or 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.

Confirm signal

All simulated exfiltration channels (fetch, sendBeacon, <img>, CSS url(), WebRTC ICE, 302 redirects) record zero hits on the Cloudflare SQLite Durable Object CanarySession under strict containment tiers.

Falsify signal

A DNS prefetch, WebRTC candidate, CSS fetch, redirect, or misconfigured sandbox combination delivers a canary token to the Durable Object collector despite an active containment tier.

What to try first

Click Run All 7 Tiers below to compare unsealed tiers that deliver canary hits against sealed tiers that block outbound requests, then open 2. Proxy/WeakSet Taint Runtime to inspect provenance tracking across transforms.

1. The Problem

Same-Origin Policy Is Not a Prompt Boundary

SOP blocks cross-origin reads, but any script or HTML fragment executing inside a first-party origin can call fetch(), sendBeacon(), images, CSS URLs, and WebSockets back to same-origin endpoints—and sandbox="allow-scripts allow-same-origin" collapses iframe isolation completely.

2. The Goal

Measure 7 Isolation Tiers Side by Side

Compare no sandbox, collapsed sandbox, opaque null-origin frames, CSP default-src 'none', DOM-less Dedicated Workers, and Chrome 152+ WICG Connection-Allowlist headers against an identical 16-vector probe suite.

3. How Verification Works

Client JS vs. Edge Durable Object

Each tier mounts a fresh sandboxed harness, fires DOM and network probes in parallel, and posts client results via postMessage(). The page then queries a Cloudflare SQLite Durable Object to confirm whether any network request actually left the browser.

How This Works & 4 Things To Try

Each tier executes probes across DOM access, fetch, sendBeacon, <img>, CSS url(), prefetch, WebSocket, EventSource, 302 redirects, and WebRTC. Results cross-check client observations with the Durable Object collector.

  1. Observe sandbox collapse: Run Tier 2 (allow-scripts allow-same-origin) to read parent.document and parent.localStorage.
  2. Compare Opaque Frame vs CSP Lockdown: Tier 3 blocks DOM reads while leaking via network; Tier 4 enforces CSP default-src 'none'.
  3. Test DOM-less Worker CSP: Tier 5 executes in a Dedicated Worker with no document global and HTTP connect-src 'none'.
  4. Test WICG Connection-Allowlist: Tier 6 sends Connection-Allowlist: () (no CSP); Tier 7 permits ONLY /api/canary/.../fetch while blocking all other vectors and redirects.

Live Boundary Architecture

Status indicators update after each run to show whether host DOM/storage and edge network boundaries held.

Host Document data-host-secret localStorage token DOM idle Selected Tier Select a tier below 16 egress/DOM probes ReportingObserver postMessage() summary Edge Collector SQLite Durable Object /api/canary/:runId 0 DO hits
Ready. Pick a tier or run all seven.

7-Tier Run Summary & Probe Matrix

Click any tier pill to filter rows. Left column = client JS observation; Right column = whether HTTP/WS traffic arrived at the Durable Object.

Tier Vector Client Observation Edge Durable Object
No probes executed yet.

Mounted Sandbox Frame

HTML tiers mount live below so interactive vectors such as the user-gesture window.open() probe can be tested directly.

Select any tier to mount its execution frame.
How This Is Set Up

Containment Boundaries & Wiring in This Lab

Replacing first-party script execution and permissive sandboxes with opaque-origin iframes, HTTP egress allowlists (Connection-Allowlist), and WeakSet/Proxy taint boundaries before untrusted text reaches network or tool sinks.

Uncontained pattern (leaks)
<!-- Same-origin + allow-same-origin collapses iframe isolation -->
<iframe sandbox="allow-scripts allow-same-origin"
        src="/sandbox/tier/2?runId=run-demo"></iframe>

<script type="module">
  // CORS only blocks cross-origin reads; outbound exfiltration still runs:
  const hostToken = window.parent.localStorage.getItem("agent_lab_host_secret");
  navigator.sendBeacon(`/api/canary/${runId}/sendBeacon`, hostToken);
  new Image().src = `/api/canary/${runId}/img?secret=${encodeURIComponent(hostToken)}`;
</script>
Contained pattern (enforced)
<!-- 1. Opaque null-origin frame; browser assigns unique origin -->
<iframe sandbox="allow-scripts"
        src="/sandbox/tier/7?runId=run-demo"></iframe>

<script type="module">
  import { TaintedSession, STRICT_SUMMARY_DECLASSIFIER }
    from "/lib/taint-engine.js";

  const session = new TaintedSession();
  const doc = session.readUntrusted("fetched_doc", untrustedHtml);
  const clean = session.declassify("summary", doc, STRICT_SUMMARY_DECLASSIFIER);
  session.callSink("send_email", clean); // throws TaintSecurityError if untainted check fails
</script>
Complete Page Setup: Tier Definitions, HTTP Headers & Durable Object Wiring

End-to-end wiring from public/index.html, public/app.js, src/headers.ts, public/lib/taint-engine.js, and src/worker.ts: the page mounts sandboxed tier frames or Dedicated Workers, the edge emits per-tier CSP or RFC 9651 Connection-Allowlist headers with Reporting-Endpoints, and TaintedSession tracks object provenance with Proxy, WeakSet, and WeakMap.

<!-- 1. Page HTML Setup (public/index.html) -->
<div class="tier-strip" id="tier-cards"></div>
<div class="sandbox-viewport" id="frame-mount"></div>
<div id="enclave-mount"></div>
<script type="module" src="/app.js"></script>

// 2. Concrete 7-Tier Capability & Header Definitions (public/app.js & src/headers.ts)
const TIERS = [
  { tier: 1, name: "Tier 1: Unrestricted", desc: "Same-origin iframe, zero sandbox, zero CSP.", sandboxAttr: null },
  { tier: 2, name: "Tier 2: Collapsed", desc: 'sandbox="allow-scripts allow-same-origin"', sandboxAttr: "allow-scripts allow-same-origin" },
  { tier: 3, name: "Tier 3: Opaque Frame", desc: 'sandbox="allow-scripts" (no CSP)', sandboxAttr: "allow-scripts" },
  { tier: 4, name: "Tier 4: Opaque + CSP", desc: "sandbox=\"allow-scripts\" + connect-src 'none'", sandboxAttr: "allow-scripts" },
  { tier: 5, name: "Tier 5: Locked Worker", desc: "Dedicated Worker + CSP connect-src 'none'", sandboxAttr: null },
  { tier: 6, name: "Tier 6: Allowlist ()", desc: "Connection-Allowlist: () (no CSP header)", sandboxAttr: "allow-scripts" },
  { tier: 7, name: "Tier 7: Scoped Allowlist", desc: 'Connection-Allowlist: (".../fetch")', sandboxAttr: "allow-scripts" },
];

// src/headers.ts — sandboxHeadersForTier(7, cleanOrigin, runId) & Tier 4/6 contracts:
const tier4Headers = {
  "X-Containment-Tier": "4",
  "Reporting-Endpoints": `csp-endpoint="${cleanOrigin}/api/report/${runId}"`,
  "Content-Security-Policy": "default-src 'none'; script-src 'nonce-...'; connect-src 'none'; img-src 'none'; style-src 'none'; form-action 'none'; base-uri 'none'; report-to csp-endpoint",
};
const tier7Headers = {
  "Content-Type": "text/html; charset=utf-8",
  "Cache-Control": "no-store",
  "X-Containment-Tier": "7",
  "Reporting-Endpoints": `ca-endpoint="${cleanOrigin}/api/report/${runId}"`,
  "Connection-Allowlist": `("${cleanOrigin}/api/canary/${runId}/fetch"); report-to=ca-endpoint`,
}; // Tier 6 emits Connection-Allowlist: (); report-to=ca-endpoint

// 3. Page Bootstrap, <iframe sandbox> Mount, TaintedSession Proxy & Edge DO Wiring
const iframe = document.createElement("iframe");
iframe.className = "probe-frame";
if (tierDef.sandboxAttr !== null) iframe.setAttribute("sandbox", tierDef.sandboxAttr);
iframe.src = `/sandbox/tier/${tierDef.tier}?runId=${encodeURIComponent(state.runId)}`;
document.getElementById("frame-mount").replaceChildren(iframe);
window.addEventListener("message", (event) => {
  if (event.data?.type === "SANDBOX_READY") {
    iframe.contentWindow?.postMessage({ type: "RUN_PROBES", secret: SYNTHETIC_SECRET }, "*");
  }
});
const { events } = await fetch(`/api/canary/${state.runId}/events`, { cache: "no-store" }).then((r) => r.json());

const session = new TaintedSession(); // WeakSet #taintedObjects + WeakMap #objectMeta + Proxy get() trap
const fetched = session.readUntrusted("fetched_doc", { metadata: { callbackUrl: "https://evil.example/drop", summary: "<p>Edge POP latency steady.</p>" } }, "https://untrusted.example/nested-json-proxy");
const cleanSummary = session.declassify("redacted_json_summary", String(fetched.metadata.summary), STRICT_SUMMARY_DECLASSIFIER);
session.callSink("external_fetch", cleanSummary); // Direct call on fetched.metadata throws TaintSecurityError
Core Plumbing Required Today (Edge Headers & Recursive Proxy Wrapping)
// src/headers.ts — connectionAllowlistHeaders() & sealedEnclaveHeaders()
// Tier 6: Connection-Allowlist: (); report-to=ca-endpoint
// Tier 7: Connection-Allowlist: ("https://origin/api/canary/:runId/fetch"); report-to=ca-endpoint
const enclaveHeaders = {
  "Content-Security-Policy": "default-src 'none'; script-src 'nonce-...' 'wasm-unsafe-eval'; connect-src 'none'; form-action 'none'; base-uri 'none'",
  "Connection-Allowlist": "(); report-to=csp-endpoint",
  "Referrer-Policy": "no-referrer",
};

// public/lib/taint-engine.js — WeakSet + Proxy taint propagation on property reads
#wrapObject(target, source, label) {
  const proxy = new Proxy(target, {
    get: (obj, prop, receiver) => {
      const val = Reflect.get(obj, prop, receiver);
      return val !== null && typeof val === "object"
        ? this.#wrapObject(val, `${source}.${String(prop)}`, `${label}.${String(prop)}`)
        : val;
    },
  });
  this.#taintedObjects.add(proxy);
  this.#objectMeta.set(proxy, { source, label });
  return proxy;
}
What disappears

allow-same-origin on untrusted frames, reliance on CORS to block outbound beacons, and unmediated string concatenation between fetched documents and privileged tool calls.

What becomes explicit

Network destinations declared per response via RFC 9651 Connection-Allowlist (() or URLPattern allowlists), explicit Reporting-Endpoints, and mandatory Declassifier checks before callSink().

Platform gaps remaining

Connection-Allowlist currently enforces in Chrome 152+ (Origin Trial 148–151) and is ignored by non-Chromium engines; JS Proxy/WeakSet taint does not survive primitive string ops without explicit derive() calls.