# Code mode, governed

> Agents run one short Python script instead of many tool calls; every inner call still passes your policy, writes can be dry-run first, and scripts never see credentials.

Source: https://neurouter.com/features/code-mode · Last updated: 2026-11-26

Multi-step work over MCP is slow and expensive: each step is a model turn, and every intermediate result passes through the context window. In code mode the agent writes one short script that does the steps and returns only what it needs.

```python
orders = acme_orders.list_orders(status="unpaid", limit=200)
late = [o for o in orders if ops.days_since(o["due_date"]) > 30]
for o in late:
    acme_orders.add_order_note(order_id=o["id"], text="Reminder sent")
return {"late": len(late)}
```

## Governed, not just sandboxed

- **Same pipeline for every inner call.** ACL, read-only checks, policies, rate limits and the audit log apply to each function call inside the script exactly as to a direct call.
- **Dry run.** In `dry_run` mode, writes return a planned change instead of a side effect. On prod, execution always starts with a dry run and the user's confirmation of that plan; writes outside the plan are refused.
- **No credentials in scope.** Scripts call functions. Tokens, base URLs and secrets stay in the server.
- **Typed stubs.** The agent gets Python signatures generated from your tools (filtered to what it may call), and scripts are type-checked before the first call.

## Sandboxed too

Scripts are a restricted Python subset (no imports, classes, files or network) run by the Monty interpreter in a separate executor process, with limits on wall time (30 s), CPU (10 s), memory (64 MiB) and tool calls (200). The worker is discarded after every run.

## When it helps

Evals run every task in both modes and recommend one per model, so you can see whether code mode helps on your API instead of assuming it. It usually pays off on multi-step tasks and makes little difference on single lookups.

Read more: [Code mode reference](https://neurouter.com/docs/code-mode) · [Security model](https://neurouter.com/docs/security-model) · [See script runs in the demo console](https://neurouter-console-demo.web.app/tasks)
