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.
Code Mode: Let the Code do the Talking
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.
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.
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.
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.
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
- works atSunil Pai works at
Cloudflare
builds agents for the Agents SDK“We work on agents at Cloudflare.”
0:15inWhy Eval++ Is the Next Great Compute PrimitiveYouTube Verified4 sources· Talk, Web· archived
- featureCode Mode: Models generate code, usually JavaScript, to run against an environment
“we asked the model to generate code, usually JavaScript, that we could run against an environment”
YouTube Unverified1 source· Talk
- featureCode Mode: Supports looping, holding state, sequencing, and parallelization
“You're able to do looping, hold state, sequencing, and parallelization”
YouTube Unverified1 source· Talk
- metric
Cloudflare API: 1.2 million tokens for a first call if every endpoint were exposed as a tool“it's about 1.2 million tokens in your first call”
YouTube Unverified1 source· Talk
- metric
Cloudflare API: About 2,600 API endpoints“The Cloudflare API surface has about 2,600 API endpoints.”
YouTube Unverified1 source· Talk
- metric
Cloudflare API: Reduced to 1,000 tokens using search and execute“It reduced that 1.2, 1.5 million token thing down to 1,000 tokens.”
YouTube Unverified1 source· Talk
- feature
Dynamic Workers: Outgoing fetches and network connections can be controlled
“we can control all outgoing fetches and network connections”
YouTube Unverified1 source· Talk
- uses
“We use V8 isolates because they start up really quickly”
YouTube Unverified1 source· Talk










