Skip to main content
All research

A script that cannot do more

Summa’s agent can batch tool calls into one short script, but every call inside it passes the same checks as a direct call, so batching never widens authority.

An agent that reads ten documents to find one number usually makes ten tool calls. Each result lands in the model’s context in full: ten documents of text, read once, mostly useless, all paid for on every turn that follows. The model needed a list of totals. It got a pile of documents.

A known answer to this is to let the model write code. Instead of calling tools one by one, it writes a short program that calls them, filters the results and returns only what it needs. Cloudflare calls this Code Mode, and Anthropic has written about the same idea as code execution with MCP. We built our own version, a tool called run_script. It is behind the code-mode feature flag and switched on only in our development environment, so this essay describes how it works, not something customers use today.

Saving context was the easy part. The hard part was making sure a script can do nothing the model couldn’t already do by calling the same tools itself.

What goes wrong with the obvious approach

The quickest way to build this is to hand the script what the tools use: a database session, an API client, the user’s tokens. Run it in the backend process and let it call tool functions directly. It works, and it quietly changes who is in charge.

Every direct tool call in Summa passes through the runtime. The runtime checks that the tool was offered to this run, validates the arguments, asks the policy engine whether the call is allowed, and counts it against the run’s budget. A script that calls tool functions in-process skips all of that. It can call a tool the run was never offered. It can pass arguments no schema checked. It can loop until the budget means nothing.

There is a subtler problem too. When the model calls a tool directly, the call is visible: one name, one set of arguments, in the open, before it runs. A script’s later calls are chosen from values computed at run time — a reference pulled out of a search result, a name parsed from a document. Nobody reviewed those values. If one of those documents was written by someone hoping to steer the agent, the script is where that text turns into action.

So batching saves context, but it must not become a second, wider door.

A sandbox with every permission off

The script runs in Deno, a JavaScript runtime that denies everything unless a flag allows it. We pass no allow flags. The process starts with --no-prompt, so a permission request fails instead of waiting for someone to approve it, and with --no-remote and --no-npm, so it can’t import code from anywhere. It has no network, no file system, no environment variables and no subprocesses.

The environment it inherits is not ours. The backend starts it with four variables — a cache directory, a home directory and two switches for update checks and colour — and nothing else. The comment beside them says why: “the backend’s secrets stay here.” Its heap is capped at 128 MB, because a script filters and joins tool results and never needs to hold files.

That leaves the script exactly one way to reach anything: an object called tools. Here is the example the model is shown:

const found = await tools.search_attachments({ query: "invoice total" });
const refs = [...found.matchAll(/\bdoc\d+\b/g)].map((m) => m[0]);
const totals = [];
for (const ref of [...new Set(refs)].slice(0, 10)) {
  const text = await tools.read_document({ document_ref: ref });
  totals.push(`${ref}: ${text.match(/total[^\n]*/i)?.[0] ?? "no total"}`);
}
return totals.join("\n");

Up to ten documents are read. Up to ten lines come back.

Every call comes home

tools is a proxy, not a library. Any property on it is a function that writes one line of JSON to standard output — a call id, a tool name, the arguments — and waits for a reply on standard input. The script never touches a tool itself. It asks.

On the other end, the backend reads each request and hands it to a caller that the runtime built for this run. That caller runs the same checks as a direct call, in this order:

  1. Offered and scriptable. The tool must be in this run’s allowed set and marked scriptable. If not, the reply names the tools the script can call.
  2. Arguments. They are validated against the tool’s own contract, the same one the model’s direct calls use.
  3. Stopped or out of budget. If the user pressed stop, or the run has no tool calls or time left, the call is refused.
  4. Policy. The policy engine must allow the call outright. A missing grant is a refusal. So is anything that would need the user’s approval.
  5. Counted. Only then is the call recorded against the run’s tool budget and executed.

The run_script call itself also counts as one call, like any other. A script that calls five tools costs six.

Approval is the interesting case. A direct call that needs approval parks the run and waits for the person. A script can’t park halfway through a loop, so the caller refuses instead: “Not permitted in a script. Call this tool directly instead.” The model can still make that call. It just has to make it in the open.

Run authority itself comes from the run’s snapshot, which is decided before any of this. We wrote about how that snapshot is taken and intersected in Permissions that only shrink. A script inherits whatever the run has. It never adds to it.

Scriptable is an opt-in, and a narrow one

A tool is not scriptable unless its definition says so. The flag defaults to false, and the comment on it gives the rule: anything that sends, changes, needs approval or reaches the open web “stays a call the model makes in the open.”

In practice that leaves read-only tools — searching and reading documents, spreadsheets and presentations, Microsoft 365 files and lists, connected file and repository sources, and the person’s work overview — plus the conversation’s sandbox. The sandbox is the one exception to read-only: a script can run commands and write files there. That sandbox is its own isolated environment, and its only network route is a proxy that admits package registries. Its export_file tool, which shares a file with the user, is not scriptable. Neither is web search, nor anything that creates, sends or changes something outside the sandbox.

A test walks the whole capability catalogue and fails if any scriptable tool breaks the rule: no web research tool, nothing but read effects outside the sandbox, no approval, nothing that publishes an artifact, visualisation, memory or resource, and never export_file. The rule is in the test suite, not only in a comment.

Limits that end a runaway script

A script may make at most 50 tool calls. The 51st gets an error back instead of a result, and so does every call after it. The script itself can be up to 20,000 characters, and the whole run of it has a time limit of 20 minutes — long enough to wait on a sandbox command, short enough to end one that is stuck.

What comes back is capped as well. The return value is cut at 200,000 characters and console output at 8,000. The model sees the return value, then any console output, as a single tool result, treated as untrusted text like every other tool result. The intermediate results never reach it.

Errors are ordinary JavaScript. A failed tool call throws an Error that names the tool and gives the reason, so a script can catch it and carry on. If the script itself throws, the model is told how many calls it made before it failed, along with the error and whatever it logged.

Two smaller details matter for correctness. Calls from one script can run at the same time, but the ones that use the database take a lock, because they share the run’s database session. And a call the script started but never awaited still finishes before the script is cleaned up. Cutting it off could leave that session halfway through a query.

Labels still work

Scripts don’t break citations. A script’s tool calls run in the same run context as direct calls, so a document it reads gets a doc label like any other, issued and stored by the server. If the script returns that label, the model can cite it as usual. How those labels work is the subject of The model never sees an ID.

The run panel shows the calls

Hiding intermediate results from the model is the point. Hiding them from the person is not. The run panel shows each script as code, followed by a list of the tool calls it made: one line per call, with a tick or a cross, the activity title and a short summary of the result. Its duration, console output and any error are shown with it. Someone reviewing a run can see exactly what a script asked for, even though the model only saw the answer.

What it costs

  • Fewer tools in a script. Anything that needs approval, sends something or reaches the web has to be a separate, visible call. A task that mixes reading and writing still takes several turns.
  • The model reads less. That is the goal, but it means the model can’t notice something in a result it never saw. The prompt tells it to use plain calls when it needs to read a result in full before deciding what to do next.
  • Text only. Tool results reach the script as text. An image from the sandbox’s read_file can’t be looked at through a script.
  • A new runtime to ship. Every backend image now carries a pinned Deno binary. If it is missing, run_script fails with “The script runner is unavailable.”
  • Not live. The feature is switched on only in development. We haven’t yet seen how models use it on real customer work.

What we would generalise

  • Batching is a context feature, not an authority feature. Any shortcut that lets a model do several things at once should route each thing through the same checks as doing it alone.
  • Give the sandbox one door. Start the interpreter with every permission off and a clean environment, and make the only way out a request the host can refuse.
  • Make the safe set an opt-in. A tool should be scriptable because someone decided it should be, not because nobody excluded it. Put the rule in a test, not only a comment.
  • What needs a person needs the open. If a call would wait for approval, it has no place inside code that can’t wait.
  • Hide from the model, show the human. Keeping intermediate results out of the context is fine. Keeping them out of the audit trail is not.