---
title: "Introducing canvas2: an agent that edits a live page while you watch"
summary: "A member playground where an agent changes a sandboxed canvas in real time, with idle checkpoints for recovery and scrawls to point at what you mean."
created: "2026-11-16"
updated: "2026-11-16"
revision: "2"
previous: "e54d9fe58ae3a3883e67bbe25e8b0c015266ccc2"
reviewedThrough: "210b5aa54b4edc6e69d64bec0a6b5cf59c5b1343"
sourceDigest: "b49c3cc7119854e253ee0b512a50b197d599afc5ae036747a92df71a5911fa58"
---

With this, a member of your mind can watch an agent build an interface while it talks: chat on the left, a live canvas on the right, and every step the agent takes changes the canvas in place. Nothing is generated as a file and reloaded. The agent edits the DOM directly, so a counter appears while the answer is still being written, and a second request changes the same elements instead of starting again. It is a playground for members, not a public app builder.

## The canvas is lent, not stored

Each browser tab is a session, and each session is an ordinary agent at `/agents/canvas2/<member user id>/<session>`, so the chat stays in that agent's log like any other. The canvas is something else: the DOM of a frame in that one tab. The page lends the agent one function on that agent's context alone, for as long as its socket is open:

```js
// in public/app.js: the lend ends when the tab closes or the session resets
const lend = await itx.cd(AGENT).provide("itx.canvas", (code) => canvas.run(code), { description });

// in the agent's own script: runs in the member's canvas, answers what it returned
await itx.canvas(`document.body.append(h("button", { id: "inc", onclick: () => document.body.dataset.count = Number(document.body.dataset.count || 0) + 1 }, "+"))`);
```

Close the tab and the name is gone from the agent's tree; its next call fails, and its instructions tell it to say so rather than pretend. Another session's agent never sees this canvas.

## A sandbox around the agent's code

The agent writes arbitrary JavaScript, so the frame is sandboxed with scripts and forms but without `allow-same-origin`, and the frame's own response carries the same sandbox in its content security policy. Its origin is opaque: no cookies of the mind, no storage, no reach into the page around it, and no way to open the member's socket. Page and frame talk only by `postMessage`, and each side checks the sender's window, its origin and a per-frame nonce. The member's page, which does hold the member's connection to the mind, never runs the agent's code. Dialogs, popups, pointer lock and top navigation are not enabled; generated interfaces should put prompts and messages in their own DOM.

## Checkpoints and scrawls

Live does not mean lost. After thirty seconds of stillness the frame takes an idle checkpoint: the DOM as HTML (typed values kept, password and card fields left out), a picture of it drawn from the DOM, and the scrawl state. The page keeps it under the agent's path and adds a passive note to the agent's context that starts no model request; the next turn a person starts can read it, and a member can ask the agent to restore the canvas from it. A restore brings back markup, styles and form values, not JavaScript state, so the agent wires the controls again. Identical states are kept once, and the number and size of checkpoints are bounded. These are best-effort recovery records, not an automatically restored live canvas. A failed picture can leave a usable DOM checkpoint, and reload or Blank canvas still empties the frame. Keep private data out of prototypes; omission of recognized sensitive form fields is not a general-purpose content scrubber.

A member can also scrawl: hold Shift and draw round the thing they mean, drop numbered pins, and type what they want. The agent gets a contact sheet of keyframes and a handle on each marked element. No microphone and no screen capture are ever asked for.

## Adapting the pattern

The frame draws pictures with `@zumer/snapdom`, loaded from a pinned module URL. The surrounding chat needs the iterate agent runtime, the UI kit and ordinary model funding; there is no screen-recording service to configure. `app.ts` guards the socket origin and serves the frame policy, `frame.html` owns execution and capture, `public/app.js` stores records and lends the function, and `agent.md` explains recovery.

Copy the `apps/canvas2/` folder, mount it behind `this.auth.require`, and point your agents backend at its `agent.md` for the session agents. Test that a signed-out visitor gets nothing, that a closed tab ends the lend, that two tabs never see each other's canvas, and that the agent's code cannot reach the page or its cookies. [Agents](/introducing/agents) explains the authenticated socket the page uses; [the blog](/introducing/blog) keeps this recipe current when the app's code changes.
