Cloudflare Code Mode
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.
Solution
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
Open the full interactive page →
Diagram, neighbourhood map, code examples, related patterns and full provenance.