An AI agent that writes one short program instead of calling tools one at a time can keep 17,783 tokens of raw results out of the model entirely. That is the headline measurement in a new explainer by Kamran Tahir on SayBackend, published 28 November 2026. The same post shows where the approach costs more and where its safety net fails.

Tahir’s test started from the 46 default tools that GitHub’s official MCP server (version 2.2.0) lists. Their definitions come to about 11,000 tokens, or 242 per tool. Tahir then pulled the 20 most recent issues from the cloudflare/agents repository, each running from 384 up to 2,572 tokens. In a normal agent loop, every one of those results passes through the model.

In code mode, the model sees a single tool that accepts code. The tools are described to it as a TypeScript API, and the model replies with a short JavaScript program. Tahir’s request: which of the 20 are open and unassigned? The program made 20 calls inside a sandbox in 6 milliseconds and handed back two issues. The 20 raw results never entered the context.

Cloudflare’s Kenton Varda and Sunil Pai introduced the idea on 26 September 2025, arguing that models have seen far more code than tool-call formats. Anthropic followed on 4 November 2025 with its own variant, where each tool becomes a file the agent reads only when needed. The Claude API also offers a managed version called programmatic tool calling, which runs Python and keeps tool results out of the model’s token count.

Anthropic’s own figures, as Tahir relays them, cut both ways. On a benchmark with 75 project-management tools, billed input tokens dropped by about 38 percent while accuracy stayed level. On τ²-bench, a test whose turns chain just one or two calls in sequence, scores held steady and cost climbed about 8 percent. These are the vendor’s numbers, not independent ones. The pattern matches Tahir’s arithmetic: the more calls a task chains together, the more the approach saves, and for a call or two the long tool description is pure overhead.

Prompt caching narrows the gap further. On the Claude API, context read again from the cache is billed at roughly 10 percent of the normal input rate, so the classic loop is cheaper than it looks. What caching cannot remove is the round trips: Tahir counts 21 model turns for the direct loop against two for code mode on the 20-call task.

The sandbox findings are the sharpest part. Tahir ran probe programs through Cloudflare’s executor. Network requests, file imports and environment variables were all refused, and the credentials live with the host, so the model’s program cannot read a key. A promise that never resolves was stopped by a 3-second timeout after 3,004 milliseconds.

A tight synchronous loop was a different story. The program while (true) {} got no response after 120 seconds. Locally, the worker process sat at 91 percent CPU and a new request went unanswered for 20 seconds. The timeout works as a timer running alongside the program, and a loop that never yields never gives that timer a turn. Tahir notes that when run on Cloudflare’s own infrastructure, platform CPU limits would halt such a Worker, and users of Dynamic Workers can set stricter ceilings.

The conclusion carries over to any executor a team builds: enforcement of the time limit belongs to the runtime, never to code running inside the sandbox. For a team deciding whether to move an agent to code mode, the test is simple. Count how many calls a typical task chains and how large the results are. Long chains over bulky data justify it; short two-step tasks may simply cost more.

Reported by Kamran Tahir on SayBackend on 28 November 2026.