Essay

Inside a mind: agents, Cloudflare and trust

In part two of taking iterate apart, I added Claude as a new kind of agent, read the one file that deploys a whole mind, studied how a lend limits access to one ability and mapped where outside text can reach an agent that holds the keys.

iteratecloudflareagentssecurityarchitecture

All writing

Where part one left off

In part one, I mapped an iterate mind from the outside: one public door, event logs everywhere, code that deploys itself, and a vault your code never reads.

This time, I wanted to build on it. The platform’s own loop calls OpenAI’s models, and I wanted to try Claude as the first step towards routing work between models. Thus, I added Claude as a new kind of agent.

Building it also answered questions that reading the code had not. Specifically, it showed why agents are shaped like this and why the platform’s own loop cannot just call Claude. It also showed who can talk to an agent once that agent can act on everything.

Since then, I have also explored lends and how people who are not members should reach a mind. Both are in the second half of this post.

Before going further, here are three terms, each in one line:

TermWhat it is
ContextAn address in the mind (/agents/email/t42) with its own append-only event log.
AgentAny context under /agents: a conversation with a title, a status, and a way to message it.
KindWhat runs an agent. iterate’s own kind is iterate; mine is anthropic.

An agent is its log

Everything an agent has seen and done is an event on its context, and the code that runs it keeps nothing that matters anywhere else. Basically, an agent is its log, rather than a process with memory.

the agent's log, oldest firstmessage-receivedturn-startedassistant-turn · step 0tool-resultassistant-turn · step 1turn-settledThe loopa facetreads, steps, writesClaudeMessages APIitxthe whole mindnothing that matters is kept in the loop: a restart reads the log and carries on
The log is the agent. The loop reads it, takes one step, writes the step down, and reads it again.

Step by step, one turn goes as follows:

  1. A member’s words land on the log. message() writes them as agent/message-received.
  2. The loop writes turn-started, rebuilds the conversation from the log, and calls Claude.
  3. Claude’s answer is written as assistant-turn, exactly as the API returned it.
  4. If Claude asked to run a script, the loop runs it against the mind and writes the result as tool-result.
  5. The loop then calls Claude again with that result, and repeats until Claude stops asking for scripts.
  6. Finally, the loop writes turn-settled, with how the turn ended.

A Claude agent of this kind has one tool, run_script, with which it writes a small async function. The function runs with itx, the handle that reaches the whole mind. Similarly, iterate’s own agents use one handle and code written against it, instead of a long list of tools.

However, the name of the first event depends on who writes it. The default template’s own channel code, for mail, Slack and X, appends agent/context-added instead. Likewise, iterate’s cost-report recipe wakes its agent with one agent/context-added. Thus, there are two names for incoming words today, and a kind has to know which one it reads.

Why the loop is a facet

My first plan was to answer messages in the mind’s event handler, processEvent, which sees every event. However, that cannot work, and finding out why taught me how the platform thinks about time.

in the event handlerin a facet, in the background20 s watchdogcut off · delivered again · cut off againrestartreads the log: step 3 is done, step 4 is nextmessagemessagesettledone turn of an Opus agent: often minutes
An event handler has 20 seconds. A facet has as long as the turn needs, and a restart only costs a re-read of the log.

The event handler gets each event with a 20-second watchdog, and if it has not returned by then, the event is delivered again. A turn of a strong model with a few scripts in it, on the other hand, takes minutes.

For this reason, the loop runs in a facet: a small Durable Object attached to the agent’s context, which the platform feeds every event of that log. It starts the turn in the background and returns at once. If the platform restarts it halfway, it reads the log, sees which step it reached and carries on. Additionally, each event it writes has an idempotency key, so a step written twice is written once.

However, a script is the one exception. If the facet dies after a script ran but before its result was written, that script runs again. Hence, scripts run one at a time, each result written on its own.

Kinds of agent

New agentAgents appiterate kindthe platform loopiterate/agentsOpenAIapi.openai.comfixed in the codeanthropic kindits own loopapps/anthropicAnthropicMessages APIyour own keyno setting points the platform loop elsewhereboth: the same log, message() and catalog row
A kind is what runs an agent. The platform's loop is OpenAI's; a kind of your own can bring any model.

Every kind shares three things: the log, message() to send it words, and a row in the agent list. Beyond those, everything else is the kind’s own: its events, its loop and its chat view in the Agents app.

My first question was whether iterate’s own loop could simply run Claude, and the answer is that it cannot. The loop sends every request to OpenAI’s Responses API at an address written into the code. Its no-key option goes through Cloudflare’s AI Gateway with openai/ put in front of the model’s name. Additionally, its settings choose a model, an effort and the keys to try, but never a provider.

Furthermore, I checked whether a router such as OpenRouter would help, since it offers a Responses-style endpoint that serves Claude. It would not, for the same reason: the address is fixed, and there is no setting for another one. Thus, a kind of your own is one of two routes for another model. The other route is a sandbox.

The second route: a sandbox

Mind agentstarts a session,then messages itSandboxClaude Code, Codexor opencode, over ACPa clone of the reporuna script againstthe mindcommitto /repos/config,which publishesEgressthe mind's own fetch,the one way outno direct internet,a key of its own per sessionthe work comes back as a commit that names its parent
A coding agent in a sandbox has two tools and one way out, and all three go through the mind.

iterate’s own mind runs Claude Code, Codex and opencode as coding agents, each in a Linux sandbox of its own. The recipe is in Let Codex and Claude Code work inside your mind, published on 12 November. One call, itx.acp.sandbox.start("claude"), starts a session, and after that you message it like any other agent.

PartWhat the sources say
SandboxA Cloudflare Container in your own account, which sleeps when idle. It holds a clone of the mind’s config repo.
ProtocolThe three agents speak the Agent Client Protocol (ACP), so one runner drives all of them.
ToolsTwo: run, a script against the mind, and commit, to the config repo. A commit names its parent, so a slower agent is refused instead of undoing another agent’s work.
NetworkNo direct internet. The platform starts the container with the internet off, and every request it makes goes out as the mind’s own itx.fetch.
KeyEach session has a key of its own, checked on every call, and one flag turns the two tools off.
Model accountEach agent needs one of its own: a ChatGPT plan or an OpenAI key for Codex, and a Claude account for Claude Code.

In other words, a sandboxed agent has two tools and one way out, and all three go through the mind.

Additionally, two cautions belong here. First, the power is real. The blog of Misha’s mind says it plainly: “with these tools, a session’s key can run any script as the mind and change the mind’s code” (Agents that commit their own config). Second, the network rule is in the public source, in core/mind-worker/src/sandbox/container.ts; however, I did not find the ACP runner in iterate/core. The post lists the runner among iterate’s own files, so it may not be in the default template yet.

What a Claude agent costs

My first few test agents cost about a quarter of a dollar in total, and the token counts the API returned show where it went:

Part of each requestShare of the cost
Writing the standing instructions to the prompt cache, once per new agentmost of it
Reading them back from the cache on later stepssmall
Claude’s own output, thinking includedsmall

Every agent reads the mind’s standing instructions before each request: AGENTS.md and the other standing files, about 19,000 tokens. Caching them makes every later step cheap; however, each new agent pays to write them once, about nine cents at Opus prices. Consequently, a short chat costs about as much as a long one, because the cost is in the instructions rather than the conversation.

How work reaches an agent

The next question was how a task finds its agent. In brief, no model decides; code does.

Member email/agents/email/t<thread>the agent's pathSlack mention/agents/slack/…/<thread>X message/agents/x/u<id>Stranger's emailworker.tswho sent it?which thread?no agent:not a member, not a reply
Routing is code, not a model: check the sender, derive a path from the thread, hand the words to that agent.

Instead, code in worker.ts handles each channel the same way:

  1. An event arrives on an integration’s log, such as /integrations/email.
  2. The code checks the sender, and each channel has its own check, as the table after this list shows.
  3. It derives a path from the thread: /agents/email/t<thread>. The same thread always gives the same path, so a reply reaches the agent that already knows the conversation. An X account is the exception, since it gets one agent per linked account: /agents/x/u<x user id>.
  4. It creates the agent if the path is new, and appends the words, with a line saying who wrote them and how far to trust them.
ChannelWho reaches an agent
EmailThree classes of sender: a member, an outside person, and another mind’s agent. A member’s own mail, sent straight from their domain, starts an agent. An outside person reaches an agent only by replying to mail that the agent sent them.
SlackA full member of the workspace whose email, confirmed by Slack, is a member’s address in the mind. Anyone else gets one short refusal.
XA linked account. The code checks that iterate Cloud signed the event, and it checks nothing about membership.

The third class of email sender is how minds work together. Mail from another mind’s agent is automated mail, yet it carries a hop count that the platform reads when the sender is proven. Specifically, three rules apply to it:

  • It reaches an agent that already wrote to that sender in the thread, marked as another mind’s agent’s words.
  • It starts a new agent only when a person has allowed the sender as a peer, by one address or a whole domain. A new mind has no peers.
  • A thread stops reaching agents at 8 hops, unless a person sets another limit.

Furthermore, only a person can set the peers and the limit; the mind’s code cannot. These rules are in the default template’s mail-replies.md.

Thus, “routing between models” is a small change in a known place: at step 4, choose which kind to create, instead of always creating iterate’s own.

Cloudflare for an AWS engineer

A mind is built from Cloudflare parts. For this reason, the table below places each part next to its nearest AWS service.

CloudflareNearest in AWSWhere the comparison breaks
WorkersLambdaCode runs in V8 isolates, not containers, so a start costs milliseconds. It runs in Cloudflare’s network close to the caller, and you are billed for CPU time, not wall-clock time.
Durable ObjectsNothing quite. Think of one Lambda per key, with its own private SQLite file.Each object has a name, runs in one place, is single-threaded, and sleeps when idle. Every context in a mind is one of these.
Service bindingsA Lambda invoking another through IAM, inside a VPCThere is no network hop and no endpoint. A Worker can only call what it is bound to, so a missing binding is a rule, not a misconfiguration.
Worker Loader (Dynamic Workers)Nothing direct. Think of Lambda loading new code from S3 into a fresh sandbox at run time.This is how a commit to the mind’s repo goes live in seconds without a deploy.
Routes and zonesRoute 53 with CloudFront in frontA route sends a hostname pattern (*.example.com/*) to one Worker.
KVDynamoDB global tables, roughlyEventually consistent and read-heavy. Good for configuration, not for counters.
D1A small RDSSQLite as a service. The sign-in Worker keeps its records here.
R2S3S3’s API, without egress fees.
QueuesSQSThe mind’s single queue of Cloudflare events retries ten times, a minute apart, then drops the message.
ArtifactsCodeCommitGit repositories as a service. The mind’s code lives in one.
ContainersFargateEach container is tied to a Durable Object. The mind’s sandboxes are containers.
Workers AI and AI GatewayBedrock, with an API gateway in frontThe Gateway puts logging, caching and spend limits in front of model calls.
Email Routing and Send EmailSESMail to the mind’s domain arrives as events.
Workers ObservabilityCloudWatch LogsLogs and invocations per Worker.

Alchemy is the last piece. One program, stack.ts, declares every resource a mind needs, and a deploy runs it against your Cloudflare account and keeps the result in a state file. Essentially, it is infrastructure as code in TypeScript, like the CDK or Terraform.

Additionally, there are two practical notes. First, a mind needs the Workers Paid plan for its full shape, because on the free plan the stack leaves out the Worker Loader, Artifacts and R2. Second, your bill has two parts: Cloudflare for the platform and your model provider for the agents.

Reading stack.ts

With that map, core/alchemy/src/stack.ts reads like a wiring diagram. It is about 550 lines, and it builds five Workers and the storage around them.

no bindingyour code: 'Bearer getSecret("/secrets/github")'Internetthe only way inBoundarythe only routessays who is callingAuthmembers, sign-inMindlogs · your repoagents · Worker LoaderSecretsthe vaultAPIGitHubDOOR: the mind's way out
The rules are bindings: only the boundary has routes, and only the boundary can reach the vault.

Specifically, it showed me five things:

  1. One public door, by construction. Every Worker but the boundary has no routes, and every one but the boundary and the optional telemetry Worker has its workers.dev address turned off. Instead, the boundary alone gets the domain and every subdomain. Thus, nothing reaches the mind except through the Worker that says who is calling.
  2. The mind has no vault binding. The boundary is bound to the secrets Worker; the mind is not. Since your code and every agent run in the mind, they cannot ask the vault for a value at all. Instead, a request with a getSecret(…) placeholder goes out through the boundary, which has the vault fill it in for the hosts that secret allows.
  3. Two speeds of deploy. Alchemy deploys iterate’s platform, rarely, and tags it with the commit it came from. Conversely, your code is never deployed: the Worker Loader loads it from the mind’s git repo when you commit.
  4. One storage primitive. A single Durable Object class sits behind every context: each agent, the email log, the repo, the agent list.
  5. You own the keys. The vault’s key and the sign-in signing key are generated in your own account at deploy, or supplied by you. Furthermore, there is a mode where the mind runs on your own machine and only the boundary stays in Cloudflare.

In other words, the rules I had read about in part one, “secrets never touch code” and “one door”, are bindings rather than conventions. Consequently, code cannot break them by mistake, because the wire it would need is not there.

Members, agents and prompt injection

The final topic is trust. A mind has two kinds of people: a member reaches everything, meaning every context, repo and secret-backed call, whereas anyone else reaches only what an app serves them. Since an agent holds the mind’s root handle, an agent can do what a member can.

Thus, prompt injection becomes a precise question of whether text written by someone who is not a member can reach a model that holds a member’s power.

stopped: no agentno gateStranger's emailHard gatecode in worker.tsOutsider's replySoft label"an OUTSIDE person…"Linked X accountSigned relayno membership checkA page it readsAgentholds the root itxas much as a memberwhat holds here: the vault,and approval rules you set
Mail is gated in code, and a linked account by its own sign-in. What an agent reads for itself is gated only by what the model decides.
PathGuardKind of guard
Email from a strangerNo agent at allHard: code decides
A reply from an outsider to an agent’s mailReaches the agent, labelled as an outsider’s wordsSoft: only the model reads the label
Mail from another mind’s agentReaches only an agent that wrote to it, or a peer that a person allowed, and stops at 8 hopsHard for who and how often. Soft for what it says.
A Slack message from someone outside the mindOne refusal, no agentHard
A message from a linked X accountiterate Cloud’s signature, and the fact that a member linked the account. No membership check.Hard, but only as strong as that account’s own sign-in
Text an agent fetches for itself: a page, an issue, a full email bodyNothingNone

The inbound channels are guarded in code. However, the X row deserves a second look. The template tells you to link a member’s own account alone, because “whoever writes from a linked account speaks to an agent with the mind’s reach”. In other words, the sign-in of that X account now guards the mind as well.

The open path is the last row: once a member asks an agent to read something, that text sits in the same context as the member’s request, and the model alone decides what to make of it.

Even so, some things still hold after an agent is fooled:

  • Secrets stay secret. The agent never has a value to leak, and a placeholder fills only for the hosts its secret allows.
  • Approval rules hold, if you set them. A rule can make an email, a named call or a request with a given secret wait for a member’s passkey. However, a new mind starts with no rules.
  • The mind’s own repo is the sharp edge. An agent can commit code, and a commit publishes. Thus, the feature that lets a mind improve itself is the same one that would let an injection outlive the conversation.

For any mind, my checklist is as follows:

  • Set approval rules for outbound mail, and for every secret that can write.
  • Keep membership small, because every member is, in effect, an administrator.
  • Where an agent only reads outside material, give it less than the root handle.

The last line is no longer only an idea, since the mechanisms for it exist today:

MechanismWhat it limits
Default-deny rewrite rulesEvery itx expression is checked against the mind’s rewrite rules, and one with no rule is refused. Thus, an agent calls only what has been named (A capability is a rewrite rule).
A key limited by pathsA program can use a key limited to one lend and its own event paths, and nothing else (CLI README).
Per-session keysEach sandbox session has a key of its own, checked on every call.

The next section shows the second mechanism in practice.

Lending one ability from a computer

eventsend()Listed personUnlisted numberThe lenda program on a Macreads the allow fileholds one narrow keyThe mindgets itx.imessage:send() and eventsnever reached: the lend refusedthe rest of Messages never leaves the Mac
A lend gives the mind one ability. The list of people and group chats, and the rest of Messages, stay on the computer.

An iMessage lend shows the idea. Messages runs on a Mac, and its database can hold more than a mind should see: other people’s conversations, and history that iCloud syncs in. A lend can expose one ability without giving the mind the database.

iterate calls this a lend. A program on the computer runs iterate provide, which dials out to the mind and lends it a name, here itx.imessage. Since the computer connects outwards, nothing on it has to be reachable from the internet. Additionally, the lend exists only while the program runs.

PartWhat it is
The lendA small program on the Mac that Messages runs on. It opens Messages’ database read-only, and it asks Messages to send.
The allow fileThe list of people and group chats, one a line. It stays on the Mac.
itx.imessage.sendWrites text or a file to a listed person or group chat. Anyone else is refused.
itx.imessage.downloadAttachmentFetches a file that came with a message the lend delivered, and nothing else.
The eventEach new message from a listed person or group chat lands as one imessage/message event on the lend’s event log.
The keyA key limited to one lend and its own event paths.

The lend is narrow on purpose. Specifically, it passes on only new messages, only from listed people and group chats, and only those written to the agent’s own account. It reads no history, and after a restart it carries on from the last message it handled. Put simply, the mind gets two functions and one stream of events, and it never sees the rest of Messages.

The key is a concrete case of “less than the root handle”: it may lend one name and add events under its own paths, and nothing else in the mind. A member can revoke the key.

I tested the lend live, and three things happened:

  1. My text reached the mind.
  2. The mind’s reply arrived.
  3. A send to a number that is not on the list was refused.

The code is in my fork, davidtandoh/iterategrations, and it follows the shape of the lends in the upstream iterategrations repository. Since then, it has gained attachments in both directions, listed group chats and a background service that starts at login.

People who are not members

The next question was how people who are not members could ask my mind for things. The simple answer would be to make them members; however, that is the wrong answer.

Signing in and being a member are two separate lists:

A memberA signed-in person
How they get thereA rule in the stack’s login.allow names them, or an owner adds them.They sign in with a mailed code or with Google, if the stack’s config opens that.
What they reachThe whole mind: its API, its MCP server and every context.Only what an app serves them.
What an app learnsWho the member is, as a principal.Their user id and their email address, and no more.
Holds itxYesNever

A member reaches everything, and an agent can do what a member can. Consequently, a person who became a member could read every context and direct an agent with my reach. For this reason, even people I trust should not become members.

Additionally, the platform keeps no allow-list for people who are not members. The rules in login.allow only make members. Once outside sign-in is open, anyone with an address can sign in. Thus, an app for named people has to keep its own list: it checks the signed-in email against its own list, and it serves nobody else.

The Requests app, a design

the words travel as data, never as an instructionRequests appnot a member, onthe app's own listMind agenttidies the request,then asks meGitHub issuelabelled, filedafter my passkeyCoding agentsread it as data,show me firstapproval 1: my passkeyapproval 2: my yesthe requester never holds itx
A design, not built yet: a request from someone who is no member travels as data and waits for me twice.

My plan for these people is a small app called Requests. It is a design, and I have not built it yet. A listed person signs in and writes what they need, and the request lands as an event.

The work itself would happen outside the mind, with coding agents that the mind cannot reach. Thus, a request has to cross from the mind to those agents, and that crossing is where prompt injection could happen. A requester’s words are outside text, like the page in the last row of the table above.

For this reason, a request travels only as data, never as an instruction:

  1. The app stores the request as an event. The requester never holds itx.
  2. An agent in the mind tidies the request, and asks me before anything is filed.
  3. If I agree, the mind files a labelled GitHub issue through a narrow GitHub app of its own. The filing waits for my passkey.
  4. The coding agents outside the mind read the issue as a request to show me. It never treats the issue’s text as an instruction, and it asks me again before any work starts.
  5. The requester hears only the state that I approved, at the address they signed in with.

In short, a request waits for me twice, and at no step do a requester’s words reach an agent as an order.

What was hard

The lend works; however, setting it up took several steps:

  1. Install the iterate CLI, and sign in to the mind.
  2. Write the allow file by hand, one handle a line.
  3. Install the background service with its key, and press Allow once on the mind’s own page.

From my perspective, the easier version is not hard to describe:

TodayEasier
Install a CLI, sign in, and set up a background service by handInstall once
A key file, and a link to press Allow onPair with a code
An allow file edited on the MacManage people from the mind

What I took away

  • The log is the system. Agents, mail and code changes are all events on logs. Code that reacts keeps nothing that matters anywhere else, so it can stop and resume at any point.
  • The rules are wiring. The one door and the vault are bindings in stack.ts rather than habits.
  • There are two routes for another model. The platform’s own loop speaks one provider. However, a kind of your own can run any model next to it, and a sandbox can run a whole coding agent beside it.
  • Lend less. A program can give a mind two functions and one stream of events, under a key that can do nothing else.
  • Signed in is not a member. People who are not members get an app with its own list, and their requests travel as data.
  • Trust is the open question. Inbound text is gated in code. Conversely, text an agent reads for itself is gated only by approval rules, and those are yours to set.

Next, I want to read the kernel itself, core/itx, and the boundary’s stamp, where “who is calling” is decided.


References