misherate blog
21 October 2026 · sandboxesagentsdurable-objects

Don't wait on the sandbox: let it call back

Misha's iterate mind runs its agents inside itself, in Durable Objects, and some of them need a real computer to run programs on.

An agent waiting on a five-minute test suite is holding a phone line open the whole time, and the next deploy hangs up on it. So we stopped waiting.

One of the mind's agents, pi, runs its whole loop inside the mind: the conversation, its storage and its files live in a Durable Object facet, and model calls go through the mind's gateway. Most of its tool calls never leave that facet. ls, grep, sed and jq run in a bash written in TypeScript over a virtual filesystem; reads fall through to the config repo at the session's base commit, writes land in SQLite, and the diff is what a commit sends.

That covers reading and editing. It doesn't cover npm install, tsc or vitest. Those need a real machine, so phase two sent them to a sandbox.

Routing a line

The shell decides per line. If every command in it is one the in-facet bash knows, it runs there; anything else goes to the sandbox:

const local = new Set(["ls", "cat", "grep", "find", "sed", "jq", "head", "tail", "wc"]);

function whereToRun(line: string): "facet" | "sandbox" {
  const commands = parse(line).commands.map((c) => c.name);
  return commands.every((name) => local.has(name)) ? "facet" : "sandbox";
}

Before a sandbox line runs, the facet's changed files go down to a plain checkout on the sandbox's disk. After it, git status on the sandbox says what the program changed, and those files come back up. node_modules/ and other ignored files never move, so an install stays on the box where it is useful.

Waiting on the sandbox

The first cut started the command on the sandbox and then waited on the sandbox for it: a long blocking call that only returned when the line had finished. That is fine for tsc. For a test suite that takes minutes, it means a call into the sandbox held open for minutes, and anything that interrupts it (a publication, a dropped connection) leaves the facet not knowing whether the line finished.

Misha's call was to stop waiting on the sandbox at all, even in long blocking waits. The sandbox says when the line ended.

# what the facet starts on the sandbox, simplified
( cd "$CHECKOUT" && bash -lc "$LINE" ) > "$OUT" 2>&1
code=$?
for attempt in 1 2 3 4; do
  curl -sf -X POST "$DONE_URL" -H "x-done-secret: $SECRET" \
    --data "{\"session\":\"$SESSION\",\"run\":\"$RUN\",\"code\":$code}" && break
  sleep 30
done

DONE_URL is a host of the mind. Its handler checks the secret and keeps the word once, as one event on the session's stream, pi/sandbox-done. The session's stream processor consumes that event and hands it to the facet, which registered its wait for that run before the line started.

// in the mind's fetch handler, simplified
if (routingSlug === SANDBOX_SLUG) {
  const done = await verifiedDone(request); // wrong or missing secret: refused
  await itx.cd(sessionContext(done.session)).append({
    type: "pi/sandbox-done",
    idempotencyKey: `done:${done.run}`, // a repeated post is kept once
    payload: done,
  });
  return new Response(null, { status: 204 });
}

Nothing asks the sandbox anything in between. If the post is lost, one look at the deadline either finds the line ended or stops it. The output (its last 256 KB) and the changed files come back in one look at the end.

Why it is better

The general lesson keeps coming back on this platform: anything that takes longer than a request should end in an event that something waits for, not in a call someone holds open.

Want this in your own iterate mind? The button copies a note for it: it reads this page, tells you what it would change, and changes nothing until you say yes.

Linking here

← Commit the manifest, not the build
Instructions grow by cases; rewrite them as a principle with examples →

One email per new post, at most two a day. Unsubscribe any time. Your address is kept privately and never shown.