| name | python |
| description | Run Python 3 snippets in the agent sandbox via tool.python: structured code, argv, and cwd. Use when you need precise numeric/data workflows, JSON/CSV transforms, or LLM-generated scripts without fragile shell quoting.
|
| tools | ["tool.python"] |
Python in the sandbox
When to use tool.python
- LLM-generated scripts — multi-line code, embedded quotes, or regex: pass them as the
code parameter instead of tool.cli + python3 -c '...'.
- Data and math — parsing JSON, CSV, statistics, date handling, quick validation.
- Reproducible snippets — same inputs as
args and optional cwd for paths relative to the workspace.
Tool shape
| Parameter | Required | Meaning |
|---|
code | yes | Full Python 3 source executed as a script file. |
args | no | List of strings → sys.argv[1:]. |
cwd | no | Workspace-relative directory; script still runs from materialized path, imports resolve relative to cwd when you cd there. |
Patterns
Print results for the model — end with print(...). Stdout and stderr are returned together (truncated per CLI max output).
Argv
import sys
print(sys.argv[1:])
Call with args: ["a", "b"].
Read workspace files — use paths under the current workspace (e.g. open("data/input.json") when cwd is set appropriately, or paths relative to workspace root).
Dependencies — the devtools image provides the stack installed there; prefer stdlib. For pip installs, use tool.cli when policy allows, or vendor small deps in the workspace.
Large code — if code is huge, write a .py file with workspace.write and run it with tool.cli (python3 path/to/script.py) to avoid command-line length limits.
Relationship to tool.cli
tool.python is isolated from CLI allowlist tiers: the runner only invokes python3 on a decoded file. Use tool.cli for pip, venv, or non-Python commands.