Full-Code · Agent SDKsactive

Cloudflare Code Mode

Type: full-code · Vendor: Cloudflare · Language: TypeScript · License: proprietary · Status: active · Status in practice: emerging · First released: 2025

Links: homepage docs

Convert MCP tools into a TypeScript API and have the model write code that calls that API, then run the code in an isolated sandbox on Cloudflare Workers.

Description. Code Mode is Cloudflare's technique for invoking tools from an agent by generating TypeScript that calls a tool API rather than emitting discrete tool-call messages. It converts Model Context Protocol tools into a TypeScript surface and asks the model to write code against it. The generated code runs in a Worker isolate created on demand through the Worker Loader API and discarded after the run. The isolate is cut off from the open Internet so the generated code cannot reach arbitrary network destinations.

Agent loop shape. The host converts available MCP tools into a TypeScript API, the model writes a code snippet that calls that API, and the snippet is run in a freshly created Worker isolate that is isolated from the Internet and thrown away after the run. Results from the executed code flow back to the model.

Primary use cases

  • calling MCP tools through generated code instead of direct tool calls
  • running model-written TypeScript in a short-lived sandbox
  • composing multiple tool calls within a single code execution

Key concepts

  • Worker Loader API code-execution (docs)The Cloudflare API that loads Worker code on demand, so a fresh isolate can be created to run the model's generated code and then discarded; this is what makes per-call sandboxes cheap enough to use.
  • V8 Isolate sandbox-isolation (docs)Cloudflare's lightweight execution unit, far cheaper than a container, that starts in milliseconds and a few megabytes; Code Mode runs each code snippet in its own isolate.
  • Bindings sandbox-isolation (docs)Capability handles given to the sandbox that provide an already-authorized client to a specific MCP server; the sandbox can reach those servers but has no general network access, and credentials never enter the generated code.

Patterns this full-code implements —

Neighbourhood

Click any neighbour to follow the lineage. Scroll to zoom, drag to pan.