Command palette
⌘K to open • ↑/↓ to move • Enter to go

Docs / How it works

Execution model

Lab is a hosted JavaScript sandbox. You send code, it runs in a fresh V8 isolate on Cloudflare's edge, and you get back a result plus a permalink to the receipt. Five concepts cover everything.

1. Isolates

Every /run request gets a brand-new V8 isolate. No shared globals, no cross-request state, no cold starts that matter. The isolate is created via Cloudflare Worker Loaders, your code runs, the isolate is destroyed.

Practically: return 1 + 1 resolves in single-digit milliseconds and the result lands in your receipt.

2. Capabilities

Code in an isolate has no host access by default. To touch KV, R2, D1, Workers AI, or to spawn a child isolate, you grant a capability on the request:

{
  "body": "return await kv.get('user:1')",
  "capabilities": ["kvRead"]
}

Without kvRead, calling kv.get throws. The denial is recorded in the receipt with a clear reason. See capabilities reference for the full list.

3. Receipts

Every run is saved. The response includes a resultId:

  • /results/:id — viewer for humans
  • /results/:id.json — canonical JSON for agents

Successful runs include the code, the granted capabilities, the per-step input and output, and timing. Failed runs include the error and reason; per-step detail may be partial. See receipt schema.

4. Chains

A chain runs multiple steps in order. Each step is a fresh isolate. The previous step's return value is the next step's input:

POST /run/chain
{
  "steps": [
    { "name": "fetch", "body": "return [1, 2, 3]",       "capabilities": [] },
    { "name": "sum",   "body": "return input.reduce((a,b) => a+b, 0)" }
  ]
}

Each step has its own capability set. The receipt shows every step.

5. Spawn

With the spawn capability, code can launch child isolates from inside a parent isolate. Useful for fan-out: 50 parallel workers, then aggregate.

const a = await spawn("return 10 * 10", []);
const b = await spawn("return 20 * 20", []);
return { a, b };

Child isolates only get the capabilities you pass to them. Depth is bounded by a per-request budget. Today the receipt records the top-level outcome and timing; per-child details aren't persisted.

Bonus: Generate

/run/generate takes a prompt, asks Workers AI to write the JavaScript, then runs it in an isolate with whatever capabilities you grant. The receipt saves both the prompt and the generated code.