Code Mode is a way of connecting large language model agents to tools. Rather than emitting one tool call per turn, the model writes a program that calls the tools as functions, and that program runs in a sandbox. The name came into wide use in 2025, when Cloudflare introduced it as a method of presenting Model Context Protocol (MCP) tools to a model as a TypeScript API.
With conventional tool calling, tool definitions and the output of every call accumulate in the context window. In Code Mode the code can chain tools with loops, conditionals and parallel calls, filter intermediate results inside the sandbox, and return only the final output to the model, which reduces token use. Anthropic described the same idea in 2025 as code execution with MCP, and coding agents, MCP servers and gateways have implemented it in various forms.