What the agent gets
Add the Code (Python) built-in to an agent (Tools, then “Add built-in”). The agent gets arun_code tool. Its description lists the agent’s other
tools as async Python functions, and a script can call any of them with
await, or several at once with asyncio.gather. A tool that returns JSON
gives the script a parsed dict or list. The value of the last line
comes back as the result, along with anything the script printed. If the
script fails, the agent gets the error and traceback and can fix it.
A script only sees the tools of the agent it belongs to.
The sandbox
Scripts run in Monty, a Python interpreter written in Rust. It has no filesystem, no network and no environment variables, and the agent’s tools are the only way out.json,
re, datetime, math, collections, dataclasses and asyncio are
available. Other standard library modules and pip packages (pandas, numpy)
are not.
Every tool a script calls goes through the same path as a direct tool call:
guardrails, metering and the run’s budget all apply.
Limits
Change them on the tool row in the agent editor, or from the CLI:
Approvals and pauses
If a tool inside the script pauses the run (ask_human, a browser approval,
wait_until), the whole run pauses, the same as a direct call. A script
cannot catch the pause and carry on. When the run resumes, the script runs
again from the top: tool calls that finished before the pause return their
recorded results instead of running a second time, and the paused call gets
the answer.
