Code Mode
With code mode, the agent gets arun_code tool. Instead of calling tools one
at a time, the model writes a short Python program that calls them as
functions, loops, filters, and computes, and gets back the program’s result
and what it printed. One model turn can do what would otherwise take many.
How it stays safe
- Programs run in Monty, Pydantic’s interpreter for a Python subset, in a separate worker process. A program has no filesystem, network, or environment access; an attempt raises an error inside the program.
- Every tool call a program makes goes through the same path as a direct tool call: governance authorizes it (a denied call raises an error the program can catch), the run’s record notes it before it starts, and it is recorded in the trace.
- A program is stopped at its time limit, memory limit (
max_memory_bytes), or tool-call limit, and its output is capped (max_output_bytes). - Under governance, running a program is its own capability (
code.run); the development profiles allow it, andstrict-productionneeds a rule.
In the trace
Each tool call a program made is listed under itsrun_code call in the
trajectory (code_calls), with its own policy decision and outcome, and each
has an ID of the form <run_code call ID>.<n>.
Approval inside a program
If a tool call inside a program needs approval, the program itself pauses: it is stored on the run’s record, signed, and the run waits like any other (Durable Runs). After the decision, the program continues from that call — nothing it already did runs again:code_mode["snapshot_key"] (or OMNICOREAGENT_CODE_SNAPSHOT_KEY) so a
paused program can continue in another process, such as after a restart; a
stored program that does not verify against the key is refused and never runs.
Without a key, a random one is used per process, so a paused program only
continues where it paused. A program too large to store (max_snapshot_bytes)
is told so instead of pausing.