Loading...
Loading...
Extend Pydantic AI agents with batteries-included capabilities from pydantic-ai-harness — currently Code Mode, which collapses many tool calls into one sandboxed Python execution. Use when the user mentions pydantic-ai-harness, CodeMode, Monty, code mode, or tool sandboxing, when they want an agent to run agent-written Python, or when a Pydantic AI agent would benefit from orchestrating multiple tool calls in a single sandboxed script.
npx skill4agent add pydantic/skills pydantic-ai-harnesspydantic-aicapabilities=[...]pydantic-ai-harnessbuilding-pydantic-ai-agentspydantic-ai-harnessCodeModeasyncio.gatherbuilding-pydantic-ai-agentspydantic-aipydanticBaseModel| Capability | Description | Reference |
|---|---|---|
| Wraps eligible tools into a single sandboxed | Code Mode |
uv add pydantic-ai-harnessuv add "pydantic-ai-harness[codemode]" # `code-mode` is also accepted as an aliaspydantic-ai-slim>=1.95.1CodeModerun_codefrom pydantic_ai import Agent
from pydantic_ai.capabilities import MCP # MCP ships in core pydantic-ai
from pydantic_ai_harness import CodeMode
agent = Agent(
'anthropic:claude-sonnet-4-6',
capabilities=[
# native=False routes the MCP tools through a local toolset so CodeMode can wrap them.
# Without it, providers with native MCP run the tools server-side and bypass the sandbox.
MCP('https://hn.caseyjhand.com/mcp', native=False),
CodeMode(),
],
)
result = agent.run_sync(
'Across the top and best Hacker News feeds, find the most-discussed story with at '
'least 100 points and summarize its comment thread in one paragraph.'
)
print(result.output)
#> The most-discussed story clearing 100 points is ...asyncio.gatherrun_codebuilding-pydantic-ai-agentsCodeModepydantic-ai-harness[codemode]ImportErrornative=TrueCodeModerun_codenative=FalseCodeModepydantic-ai-harness[codemode]