Skip to main content
connic
Back to BlogAnnouncement

Introducing connic sandbox: 2x Faster Agents, 64% Fewer Input Tokens

connic sandbox lets AI agents call their tools from Python with one YAML setting. In our test, runs took half the time and used 64% fewer input tokens.

December 1, 20267 min readAuthor: Emil Milow

Today we are shipping connic sandbox. Agents get a tool that runs Python, and with tool code mode they call their own tools from that code. In our test with two tasks of 10 to 13 tool calls and large results, runs in tool code mode took less than half as long as runs with direct tool calls on average and sent 64% fewer input tokens to the model.

Let agents run code

A model is good at deciding what to calculate. Adding up 20 order totals or comparing dates in its head costs output tokens, though, and now and then a digit comes out wrong. Python doesn't make that kind of mistake.

A sandbox block in the agent's YAML gives it the run_code tool. The agent writes Python, connic runs it, and the agent gets back the value of the last expression and anything the code printed. When the code fails, the agent reads the error and can fix the code.

agents/order-analyst.yaml
sandbox:
  enabled: true

The code can use a set of standard library modules, such as json, csv, re, datetime, decimal and statistics. The sandbox has no network, no file system and no packages, so the code sees only what the agent passes in or fetches through its tools. Variables stay defined between run_code calls in the same run, which lets an agent load data once and keep working with it. Each call runs for up to 30 seconds, and time spent waiting for tools doesn't count.

The agent's file tools work inside the code. An agent can read a CSV export from connic files, filter it and write a report, and the file's rows never pass through the model:

run_code
import csv

export = await file_read(path="exports/orders.csv")
rows = list(csv.DictReader(export["content"].decode().splitlines()))
late = [row for row in rows if int(row["days_open"]) > 7]

await file_write(
    path="reports/late-orders.csv",
    content="id,total\n" + "\n".join(f"{row['id']},{row['total']}" for row in late),
)
len(late)

Tool code mode: tools become functions

With direct tool calls, every result lands in the model's context. An agent that lists 44 open orders and then looks up their customers reads every line item and shipping address on the way, and each further model call in the run sends all of it again.

With tool_code_mode: true, the agent's tools become async Python functions inside run_code. The sandbox is on as soon as the block exists, so this one setting is enough:

agents/order-analyst.yaml
tools:
  - shop.list_orders
  - shop.get_customer

sandbox:
  tool_code_mode: true

The agent sees each tool as a Python signature with its description. It can now fetch the orders, look up the customers in parallel, filter and add up in one step. The tool results stay in the sandbox, and the model gets back ten order IDs and one total:

run_code
import asyncio

orders = await list_orders(status="open")
customer_ids = {order["customer_id"] for order in orders}
customers = await asyncio.gather(*(get_customer(customer_id=cid) for cid in customer_ids))
gold = {c["id"] for c in customers if c["tier"] == "gold"}
late = [o for o in orders if o["customer_id"] in gold and o["days_open"] > 14]
sorted(o["id"] for o in late), round(sum(o["total"] for o in late), 2)

This also works with discoverable tools. The tool search returns the signatures, and the agent calls the tools it found in its code.

Half the time, 64% fewer input tokens

We measured tool code mode on a synthetic order book. One tool lists the 44 open orders, about 20,000 characters of JSON with line items and shipping addresses. A second tool returns a customer profile with its tier. Task A asks which orders of gold customers have been open for more than 14 days, with their IDs and total. Task B asks for the value of open orders per customer tier.

Claude Sonnet 5.5 and Gemini 3.8 Flash ran each task twice with direct tool calls and twice in tool code mode, with the same prompt and tools. Each row shows the average of two runs, and output tokens include thinking:

ModelTaskModeInput tokensOutput tokensModel callsTime
Claude Sonnet 5.5ADirect21,2681,5743.014.2 s
Claude Sonnet 5.5ACode6,915 (−67%)6803.57.8 s
Claude Sonnet 5.5BDirect21,6881,6883.014.7 s
Claude Sonnet 5.5BCode5,261 (−76%)4293.06.0 s
Gemini 3.8 FlashADirect14,8504,9173.037.8 s
Gemini 3.8 FlashACode11,263 (−24%)1,3665.520.2 s
Gemini 3.8 FlashBDirect18,3686,6283.542.3 s
Gemini 3.8 FlashBCode4,196 (−77%)8234.014.6 s

Across all runs, input tokens fell from 19,043 to 6,909 per run on average, 64% fewer. A run took 12.1 seconds on average instead of 27.2. All 16 runs gave the correct answer.

Output tokens including thinking fell by 78%, for both models on both tasks. On task A, Gemini 3.8 Flash wrote its code over several steps and needed 5.5 model calls instead of 3, and it still finished in 20.2 seconds instead of 37.8.

In an earlier round of the same test, one direct Sonnet run added up a tier total in the model and reported €4,053.85 instead of €4,052.85. In tool code mode, Python calculates the totals, and every one came out exact.

The sample is small, and both tasks were built for many tool calls and large results. The numbers for all 16 runs are in the benchmark data.

When tool code mode pays off

Tool code mode helps most when an agent makes many tool calls per task, gets large results back, or combines and adds up data from several tools. For an agent that makes one tool call per task and passes the result on, it adds little, because the model still writes that call, now as code. It stays off until an agent's YAML turns it on.

Some tools stay separate tools in tool code mode: tools that need approval or a person's input, tools that show a UI, the tools that connect a user's account, and the browser tools. The agent calls them as before, so approvals and app UIs work unchanged. Voice agents can use run_code, but not tool code mode.

To measure the effect on real traffic, add a variant of the agent with tool code mode and compare cost and latency in an A/B test.

Same rules, full trace

A tool call from code runs like a direct one. Tool hooks run before and after it, access rules decide what it may read and change, and test mocks replace it in tests.

In the run's trace, a Run Code span shows the code the agent wrote, with every tool call from that code nested under it. A reviewer sees which customers the code looked up and what each lookup returned.

Trace of a connic agent run in tool code mode: a Run Code span with the Python the agent wrote, and the get_customer tool calls from that code nested under it
A Run Code span from the benchmark: the code the agent wrote, with the customer lookups it made nested under it.

Get started

  1. Install the connic plugin. Skip this if your coding agent has it already. Paste this into Claude Code, Codex or Cursor:

    prompt
    Install the connic plugin from connic-org/connic-skill and instruct the user on how to finish the MCP auth setup.
  2. Give your agents a sandbox. Paste this into a new session in your connic project. Your coding agent works out with you which agents benefit, adds the sandbox and deploys:

    prompt
    I'd like my connic agents to use the sandbox. Look at the project and tell me which agents make many tool calls per task or get large tool results back, and which ones calculate or parse data. Propose which agents should get `sandbox` with `tool_code_mode: true` and which only need `run_code`. Once we agree, update the composer SDK to the latest version, add the `sandbox` block to those agents, validate the project, deploy it to my connic project and tell me where to compare input tokens and run time before and after.
  1. Update the composer SDK. The sandbox needs the latest version:

    pip install --upgrade connic-composer-sdk
  2. Add the sandbox block. In an LLM agent's YAML, a sandbox block adds run_code (enabled: true is the default), and tool_code_mode: true moves the agent's tools into the code.

  3. Deploy and compare. Send the same input before and after, and compare input tokens and duration in the run details. The Run Code span shows the code and its tool calls.

Give your agents a sandbox

Turn on run_code and tool code mode for your first agent.

Frequently Asked Questions

The code is Python and can use a set of standard library modules, such as json, csv, re, datetime, decimal and statistics. It has no network, no file system and no packages. Code reaches data only through the agent's file tools and, in tool code mode, the agent's other tools.

When an agent makes one tool call per task and passes the result on. The model still writes that call, now as code, so there is little to save. The gains come from many tool calls, large results and data combined from several tools.

Yes. Tools that need approval or a person's input stay separate tools, as do tools that show a UI, the tools that connect a user's account, and the browser tools. The agent calls them directly, and the approval flow is unchanged.

Yes. A tool call from code runs like a direct call: tool hooks run before and after it, access rules apply, test mocks replace it in tests, and it appears in the trace.

Voice agents can use run_code, for example to calculate during a call. Tool code mode is not available for them.

In the run's trace. A Run Code span shows the code the agent wrote, with every tool call from that code nested under it.