Code Mode: Let Agents Write the Glue Code
An agent should not need another model turn to join two arrays. Yet plenty of workflows ask it to fetch records, read every row, copy identifiers into another call, and then explain the result. We have made a very expensive data pipeline with excellent conversational skills.
Code Mode offers a useful alternative: let the model write a short program that calls tools, handles the intermediate data, and returns the evidence needed for the next decision. I’d use it where the work is mostly composition. A loop does not become more intelligent because a language model narrates every iteration.
This is an established pattern, not a new November launch. Cloudflare described its MCP-to-TypeScript approach in September 2025, and Anthropic’s November 2025 engineering article explains how code execution can keep large intermediate results out of the model’s context. Neither makes every agent faster by default.
Give the model a smaller job
Consider a hypothetical support workflow: find open, high-priority tickets with a breached SLA for enterprise accounts, then prepare an exception brief for a service manager. The account plan lives in the CRM. Ticket status and SLA state live in the support system.
The model needs to understand the request, select the right operations, and explain the exceptions. Fetching pages, deduplicating account IDs, joining records, and counting matches are ordinary program logic. Moving those steps into code means the model can receive the relevant ticket IDs and coverage information instead of both raw datasets.
Push filtering into the source API first. If one authorized backend query already produces the answer, use it. Downloading an entire database into a sandbox and celebrating the smaller prompt is a questionable victory.
For the remaining cross-system join, a generated read-only program might look like this. These are illustrative application APIs. Assume the support endpoint supplies an explicit SLA flag, both connectors enforce the caller’s access, and the CRM batch method returns only authorized records.
async function buildExceptionBrief(support, crm) {
const tickets = [];
let cursor;
do {
const page = await support.listTickets({
status: "open", priority: "high", cursor,
fields: ["id", "accountId", "slaBreached"]
});
tickets.push(...page.items);
cursor = page.nextCursor;
} while (cursor);
const ids = [...new Set(tickets.map(t => t.accountId))];
const accounts = new Map();
for (let i = 0; i < ids.length; i += 100) {
const batch = await crm.getAccounts({
ids: ids.slice(i, i + 100), fields: ["id", "plan"]
});
for (const account of batch.items) {
accounts.set(account.id, account);
}
}
const unresolved = tickets.filter(t =>
!accounts.has(t.accountId));
const matches = tickets.filter(t =>
t.slaBreached === true &&
accounts.get(t.accountId)?.plan === "enterprise");
return {
complete: unresolved.length === 0,
checkedTickets: tickets.length,
unresolvedTicketIds: unresolved.map(t => t.id),
matchingTicketCount: matches.length,
ticketIds: matches.slice(0, 100).map(t => t.id),
truncated: matches.length > 100
};
}The useful output is not just a shorter list. It says how much was checked, whether account lookups were unresolved, and whether the displayed matches were truncated. A missing account is not silently treated as a non-enterprise customer. A rejected API call throws; it does not become an empty successful batch.
This is an outline, not production-ready integration code. Add validated response schemas, explicit dataset and execution limits, cursor-loop detection, and source timestamps. If the two systems cannot provide a consistent snapshot, describe the result as observations collected over an interval, not a perfectly synchronized view.
Discovery and execution are separate decisions
Cloudflare’s current Code Mode documentation exposes tools as typed methods and supports connector-based discovery through search and describe operations. Its @cloudflare/codemode package is still marked experimental. Pin the version and verify the integration surface before building against an example.
I’d discover the support and account methods first, inspect their inputs and result shapes, then generate the join. Guessing a method name inside a long script simply moves the failure later. Keep descriptions explicit about pagination, maximum batch size, omitted fields, and whether an operation changes state.
The runtime matters as much as the syntax. Cloudflare distinguishes its isolated executor, service connectors, and durable runtime. The executor runs code; the runtime owns execution history and replay. A sandbox alone is not a workflow engine.
Anthropic’s programmatic tool calling applies a comparable idea through its code-execution container, but the integration is different. Its current documentation excludes tools supplied through the native MCP connector from programmatic calls. A shared architectural pattern does not imply interchangeable product APIs.
One outer call can still hide many effects
A script that looks like one tool call to the model can make dozens of service calls. Count and authorize those calls at the connector boundary. Keep credentials in the host, bound each operation to the actual user and tenant, and expose only the capabilities the task needs.
For this example, that means read-only support and CRM access. The generated code cannot upgrade itself to sending customer messages or changing account plans. Treat ticket text as data; do not evaluate it as code or let it redefine the task.
Batching is useful when the API supports it. Parallel reads can help when they are independent, but concurrency should respect service limits. A hundred simultaneous requests are still a hundred requests, even if the prompt contains one Promise.all.
Writes deserve a separate boundary. If a later version of the workflow assigns tickets, keep that action behind its own authorization and a reviewed target set. A preview produced from yesterday’s records should not silently become today’s bulk update.
Keep failures visible and measure the whole job
Suppose the support read succeeds and the third CRM batch times out. Returning the first two batches as a complete exception list would be wrong. Fail the report, or return an explicitly partial result with the affected scope. Decide that behavior in the application contract before asking the model to improvise.
For read retries, account for changing source data. For writes, retrying the entire generated script can repeat earlier effects. Durable call records, stable operation identifiers, and reconciliation belong outside ephemeral execution. Those are requirements to design, not properties granted by the phrase Code Mode.
I’d compare the direct-call and code paths on the same representative tasks. Measure completed-task correctness, total latency, billed model and execution cost, service calls, and recovery effort. Include missing accounts, later-page matches, rate limits, malformed responses, and ambiguous failures.
Keep direct tool calls when one or two small results need interpretation before the next step. If the workflow has become fixed and predictable, move the proven logic into a maintained function or backend endpoint. Having an agent regenerate the same integration every morning is not much of an abstraction.
Start with one read-only join whose intermediate data is much larger than its useful answer. That is a credible place to test the pattern. Give the model the decisions, let code handle the plumbing, and keep the operational contract in software you can inspect.
Key takeaways
- Use Code Mode for tool composition, joins, loops, and filtering when intermediate data would otherwise dominate the model’s context.
- Filter at the source first and return coverage, missing-data, and truncation information alongside the selected results.
- Enforce access and execution limits at the connector boundary; generated code and a single outer call do not expand authorization.
- Treat partial failures and write retries explicitly, and measure complete-task cost and correctness before adopting the pattern.

Chief Technical Officer
