What happened
CodeMode exposes eligible tools through a single run_code tool; calls made by the code are dispatched through Pydantic AI to the host tools. The snippet can use loops, conditionals, variables and asyncio.gather. Pydantic’s example fetches 10 items, filters them in the sandbox and returns three matching names.
By default, tools='all' puts every eligible regular tool inside Code Mode. Approval-required tools, external tools, framework control tools and other code-execution tools remain native by default.
Why it matters
For workflows that need tool calls composed and their output reduced before it reaches the model, a constrained Monty runtime offers a clearer execution boundary. IPython is a different trust decision: code runs with the permissions of the agent’s user, so it should not handle untrusted input in a webserver without a sandbox around the agent.
Limits and uncertainty
Pydantic says the Harness API may change between minor releases while it remains on 0.x.
Skill to build now
Install the Monty extra with pip install "pydantic-ai-harness[codemode]", add CodeMode() to the agent’s capabilities, then register tools as usual. To limit the tools available inside run_code, configure CodeMode(tools=['search', 'fetch']); nonmatching tools remain regular calls.
Reader takeaway
Code Mode is useful when an agent needs to call tools, combine results and return only relevant data. Pax enables it by default; Harness developers can narrow the tools exposed inside run_code. The runtime boundary matters: Monty constrains execution, while IPython runs code with the agent runner’s permissions.