Sunil Pai, creator of PartyKit and agent infrastructure engineer at Cloudflare, presents "Code Mode" — a paradigm shift in AI agent interaction where models generate and execute code (primarily JavaScript) rather than making traditional JSON-based tool calls. The talk draws on Cloudflare's internal experience scaling agent systems and argues that code generation is a fundamentally superior interface for LLMs interacting with complex systems.
Pai opens with a core problem: traditional tool calling breaks at scale. Once an agent environment is loaded with Google services, Jira, wikis, and similar integrations, hundreds of tools fill the context window, causing degraded performance, slow round-trips, and compositional failures. Cloudflare's API surface encompasses roughly 2,600 endpoints — naively exposing one MCP tool per endpoint would consume approximately 1.2 to 1.5 million tokens on the first call, making it completely impractical.
Pai's colleague Matt Carey developed a solution: expose just two tool calls — search and execute — both of which accept code strings as inputs. The search function takes the full OpenAPI JSON spec as its argument; execute exposes callable functions against the resolved endpoints. This approach reduces the 1.2-million-token problem down to roughly 1,000 tokens — a 99.9% reduction. A live demo on stage (with acknowledged live-demo jitters) showed the agent handling a DDoS mitigation request by generating JavaScript that paginated through Cloudflare's IP blocking APIs in a single execution pass, versus the eight round-trips a traditional MCP flow would require.
Code generation unlocks fundamental programming primitives that JSON tool calling cannot provide: looping, stateful execution, sequencing, parallelization, and type-checked APIs with syntax errors. Because models are trained on terabytes of code, they are already fluent in this interface.
Pai then shares a more conceptually striking example: Cloudflare Workers creator Kenton built a personal whiteboard coding canvas. When he asked the model to play tic-tac-toe with him, the model — instead of generating a tic-tac-toe application — inspected the raw canvas state (an array of strokes), recognized the board and the X in the top-left corner, and drew an O in the middle. No tic-tac-toe logic existed anywhere in the system. Pai describes this as the model "inhabiting the state machine" rather than generating a separate program — a Ghost in the Shell reference included. A notable aside: reasoning traces revealed that Claude Opus deliberately let Kenton win, raising alignment questions Pai does not attempt to resolve.
The architectural pattern that emerges is what teams are calling a "harness": a sandboxed runtime — Cloudflare uses V8 isolates with roughly 10 years of security hardening — that starts with zero capabilities. Capabilities (APIs, network access) are explicitly granted, all outgoing fetches are controllable, and full observability is mandatory. Pai emphasizes absolute audit trails: "You need to know why last Tuesday it made a trade for $2.3 million for llama poop or something."
From this harness foundation, Pai projects further possibilities: long-running workflows lasting days or months, per-instance stateful execution, and generative UI — fully custom interfaces rendered per user based on their context (cart state, preferences, support history) rather than the lowest-common-denominator UIs that currently dominate e-commerce. He frames the next billion users of these systems as agents that "dream in types and syntax errors" and calls for developer experience investment in agent-oriented documentation (Markdown docs, actionable error messages, discoverability via search).
Pai closes by framing the historical shift: programmers have always had infinite power to interact with systems through code, while everyone else got buttons and forms. LLMs are erasing that distinction. The prescription: build systems where the code does the talking, design for capability-based security from the ground up, and reckon with the fact that your primary API consumers may soon be code-generating agents rather than human developers.
[music] >> Our next presenter created PartyKit, the open-source tool for real-time multiplayer apps. For his day job, he builds AI agents at Cloudflare. Please join me in welcoming to the stage Sunil Pai. Uh 20 minutes to the pub. Uh hi. Uh my name is Sunil Pai. Uh I work at Cloudflare. Uh I build agents over there uh for the agents SDK. I'm trying very hard for this not to be a Cloudflare talk, but I think we are on the sponsor board, so that's nice. Uh this is a talk about something we call co...
Mario Zechner, creator of the LibGDX game framework, delivers a provocative three-act talk about building a minimal codi...