WhoBuilt

Code Mode: Let the Code do the Talking

Apr 19, 2026· 20 min· 13K views·Watch on YouTube

Speaker

Sunil Pai, who builds agents for Cloudflare’s Agents SDK, presents Code Mode to an AI Engineer audience, drawing on Cloudflare API examples and a colleague’s canvas experiment.

Why tool calling gets unwieldy

Pai says tool calling works with a few tools, but large collections of services can overwhelm context and require slow back-and-forth. He proposes having a model generate JavaScript to run against an environment, using code’s types, loops, state, sequencing, and parallel execution.

A smaller interface for a large API

The Cloudflare API has about 2,600 endpoints; exposing them all would require roughly 1.2 million tokens. Pai describes a design with just two tools, search and execute, that accepts code and reduces the initial token load to about 1,000. He illustrates the approach with a request to find and block IPs involved in a DDoS attack, then demonstrates listing Workers; the live demo encounters errors.

Models can work with system state

Pai argues that generated code can let people interact with systems without a prebuilt app for each task. As an example, Cloudflare’s Kenton built a drawing canvas and asked a model to play tic-tac-toe by inspecting the strokes and adding a move. The model recognized the board and responded without any tic-tac-toe logic in the canvas.

Run code with explicit capabilities

Pai describes a harness that provides a sandbox for generated code and grants it specific capabilities. In his account, Cloudflare uses V8 isolates and exposes APIs while controlling network access; he recommends starting with no outgoing fetches and granting access deliberately. He also stresses speed and observability, so teams can inspect what code ran and why.

Design systems for agent interaction

Pai sees potential for long-running workflows with persistent state and custom interfaces tailored to each user, such as returning shoes while finding alternatives under $100. He says systems should be discoverable by agents through Markdown documentation, useful errors, and search, with capability-based security as a core design concern. He frames this as a new way for software to interact with the systems people use.

Takeaways

  • Keep large API surfaces out of the model’s initial context; let it search and execute against a smaller interface.
  • Use generated code when a task needs loops, state, sequencing, or parallel calls across services.
  • Run generated code in a fast sandbox with explicit capabilities and controlled network access.
  • Make systems easier for agents to use with searchable interfaces, Markdown documentation, and actionable errors.
  • Consider task-specific workflows and interfaces where a fixed app cannot anticipate each user’s needs.

Mentioned in this talk

Search inside this talk

What was claimed 8

Related talks