Step 2: reference architecture

A reference architecture for governed AI agents on Cloudflare

Four layers, four kinds of control point, and one change followed from ticket to production. Where each of the seven jobs is done, and which Cloudflare product does it.

Step 1 listed seven jobs. The reference architecture shows where each one is done. It has four layers: identity, session, control points and resources. A control point is a place where a rule is checked and the request is logged. Every exit from the session passes one. Two side columns hold state and evidence. At the end, one change is followed through all of it.

1 Identity 2 Session 3 Control points 4 Resources Your identity provider Access: one identity per request Agent harnessModel, tools, skills, rulesExtensions written as codein version control Disposable runtimeContainers + Durable ObjectBroad rights inside, no secretsgone when the session ends Web Gateway policies, DLP, Browser Run Tools MCP portal, Code Mode Infrastructure Access for Infra, Mesh or Tunnel Models AI Gateway, routes, budgets The web published apps MCP servers tickets, code, ERP Servers firewalls, clusters Model providers hosted or own Side column: state R2 storageOne encrypted bucketper person.Company content,from Git, read-only Side column: evidence LogsAccess, Gateway andAI Gateway recordwho did what, underwhich policy and atwhat cost.export to your SIEM
Four layers, with state and evidence at the side. Read it from the top down.

The four layers

1. Identity

Every request carries one identity. Engineers sign in through Access with your identity provider, and device posture checks can apply. The same identity then follows the request through the layers below. AI Gateway behind Access records the verified user ID, MCP server portals and Access for Infrastructure see the same user, and the logs tie everything together.

Runs without a person, for example from a ticket or a schedule, need a service identity. Define it explicitly and limit what it may do.

2. Session

The session is where the agent runs. Make it disposable. On Cloudflare this is Containers controlled by a Durable Object. Sandbox packages the pattern, with a terminal in the browser.

Inside, the agent can have broad rights, because nothing valuable or secret lives there. Credentials stay outside: an outbound handler in your Worker adds them after a request leaves the container.

The agent is a model in a harness. The harness is the program around the model that runs the loop, with tools, skills, rules, memory and extensions. Write the company's guidelines and workflows as extensions, keep them in version control and install them at startup. The model answers differently each time, but the extensions behave the same. You can run a harness as a command-line agent in the container (Sandbox coding agents) or in a Durable Object with the Agents SDK (Pi, OpenCode, Think).

Ending a session does not undo a git push, an API call or a change on a server. This is why the control points matter.

3. Control points

A container with Internet off reaches only the hosts you allow. Everything else leaves through one of four control points.

Web. The outbound handler sends requests through a Workers VPC network binding with network_id: "cf1:network". Public Internet traffic then leaves through Cloudflare Gateway, your existing Gateway policies apply, and the requests appear in the Gateway logs (changelog, 5 June 2026). Data loss prevention (DLP) and antivirus scanning belong to the same policy engine. Publish internal resources behind Access and allow nothing by default. For pages that need a browser, Browser Run offers headless Chrome and a /markdown endpoint that turns a script-heavy page into Markdown before it enters the context.

Tools. Connecting many Model Context Protocol (MCP) servers directly to an agent fills the context with tool descriptions. An MCP server portal is one endpoint in front of all servers. You connect each server once, and the portal handles authentication toward it. With Code Mode, the agent sees two tools, search and execute.

Infrastructure. Access for Infrastructure supports SSH. You define targets, tag them and choose which UNIX users an identity may use. Access logs and command logs record what happened. Mesh or Tunnel provides the route. Give agents least privilege, and require approval for changes.

Models. AI Gateway is the one endpoint for model calls. Dynamic routes send different groups to different models, set rate and budget limits and define fallbacks. Guardrails and DLP check prompts and responses. Logs record model, token use and cost.

Gateway DLP and AI Gateway DLP share a name and detection engines. Gateway DLP checks what leaves over the network. AI Gateway DLP checks prompts and responses.

4. Resources

The control points reach four kinds of resource: the web and published internal apps, MCP servers, infrastructure targets, and model providers. A model provider can be hosted, or a model you run yourself. AI Gateway reaches your own models as a custom provider, over Mesh or Workers VPC. Companies with idle devices, such as workplace machines and workstations, can serve open models from them and use that capacity for sensitive or routine work.

Two side columns

State. The session is disposable, so keep state elsewhere. Use two stores in R2:

  • A bucket per person for skills, rules, memory and configuration, encrypted with keys that belong to that person. R2 encrypts all objects at rest, and SSE-C lets you supply the key. You design key handling and rotation, and Secrets Store can hold master keys.
  • A company-managed store, filled from a Git repository with review, applied when a session starts and read-only for the person.

Container snapshots cover short breaks. A snapshot expires 30 days after it was created or last restored, so move longer-lived files to a bucket. Who owns a person's accumulated memory is a business decision. Step 1 lists it.

Evidence. Access, Gateway and AI Gateway logs show who did what, under which policy, and at what cost. Send them to your security information and event management (SIEM) system with Logpush.

One change, end to end

Take a certificate that is about to expire on an internal service. This is how the layers work together.

Step What happens Layer Cloudflare building block
1 An engineer opens a session in the browser Identity, session Access, Sandbox terminal
2 The session starts with the company rules and the engineer's own skills State R2
3 The agent reads the ticket and the repository Tools MCP server portal
4 The agent asks a model for a plan. The route picks a model, DLP scans the prompt and the call is logged with the user Models AI Gateway
5 The agent reads the vendor documentation Web Outbound handler, Gateway, Browser Run
6 The agent logs in to the server with read-only rights and collects diagnostics Infrastructure Access for Infrastructure, Mesh or Tunnel
7 The agent writes a change plan and opens a pull request Tools MCP server portal, your Git
8 CI runs, and a person reviews and approves the merge and the change Outside Cloudflare Your pipeline and approval flow
9 The session ends. Skills and notes stay in the personal bucket State R2
10 Security reviews the evidence Evidence Access, Gateway and AI Gateway logs

Going further

Once a task runs well under supervision, it can run on its own. Build autonomous agents with the Agents SDK and Workflows, behind the same control points. Dynamic Workers start isolated Workers on demand, and the calling Worker decides which bindings each one gets. Decide which identity an unattended run uses and what it may do. Gartner's four autonomy levels from Step 1 map onto this: observe and advise need read access, act with approval opens write access behind an approval step, and act autonomously opens it within guardrails.

What you still own

  • The harness extensions and the rules behind them.
  • The session lifecycle: timeouts, alarms, snapshots and clean-up.
  • The pipeline that fills the managed store, and key handling for the personal buckets.
  • The policy that maps groups to routes, tools and SSH users.
  • Approval flows, and the identity for unattended runs.
  • The delivery pipeline: git, CI, branch protection and the human merge.
  • If you serve your own models: the runtime and the routing in front of it.
  • The incident path: who can revoke an identity, a route or a session.

I built this from the documentation and checked it on 9 November 2026. Check the linked pages for current details before you commit to a design.