Approach

Code Mode

Cloudflare's approach to tool use by AI agents: instead of calling MCP tools one by one, the model writes TypeScript against an API generated from MCP servers, and the code runs in an isolated sandbox. Introduced in September 2025 by Kenton Varda and Sunil Pai.

The argument is simple: language models have seen a huge amount of real code and very few examples of tool calls, so they handle a TypeScript API better. And the code works through the chain of calls itself and returns only the result, rather than routing every intermediate result through the model. It runs in V8 isolates via the Worker Loader API: each code snippet gets a fresh isolate that starts in milliseconds. The sandbox has no internet access, reaches MCP servers through bindings, and access keys are injected by an outside process, so they never appear in the generated code. In November 2025 Anthropic described the same technique in a post on code execution with MCP. In February 2026 Matt Carey showed Cloudflare's MCP server in Code Mode: two tools, search() and execute(), cover more than 2,500 Cloudflare API endpoints and take up about a thousand tokens of context instead of 1.17 million. In October 2026 Earendil's Pi agent gained MCP support through Code Mode.

In the episodes

2