Python Execution
The python tool lets agents execute Python code in their sandboxed workspace. It’s useful for data processing, calculations, file manipulation, and anything that’s easier to express as a script than a shell command.
python( code: "import json\nwith open('data.json') as f:\n data = json.load(f)\nprint(len(data['items']))")Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
code | string | yes | Python code to execute |
How it works
Section titled “How it works”The code runs with python3 in the agent’s workspace directory. Standard output and errors are captured and returned to the agent as a tool result.
Execution has a 30-second timeout. If the script exceeds this, it’s killed and the agent gets a timeout error.
When to use python vs. shell
Section titled “When to use python vs. shell”| Scenario | Tool |
|---|---|
| Data processing and analysis | python |
| File parsing (CSV, JSON, XML) | python |
| Math and calculations | python |
| Installing packages, running builds | shell |
| System commands (ls, curl, git) | shell |
| Quick file operations | shell |
Sandboxing
Section titled “Sandboxing”Python execution runs inside the same sandbox as the shell tool. Filesystem access is restricted to the agent’s workspace, and network access is controlled by the agent’s sandbox settings.
See CLI Execution for sandbox configuration details.