Python Tool
The model is bad at long arithmetic and data wrangling. A kernel is good — and dangerous.
A lab bench behind glass. Useful. Not the keys to production.
Visual Workflows
Start here — scroll inside each diagram frame to explore, then use + / − to zoom up to 200% if needed.
Overview
Scroll inside the frame to explore · use + / − to zoom up to 200%
Scroll inside the frame to explore · use + / − to zoom up to 200%
Exec path
Scroll inside the frame to explore · use + / − to zoom up to 200%
Validate, run in sandbox, return a small result.
Key Takeaways
- 1.A Python tool runs code the model wrote — calculate, transform, plot. Sandbox it: no network, no secrets, time and memory caps.
- 2.Return stdout and a short error, not a traceback novel. Prefer a calculator tool over free exec when you only need math.
- 3.Restricted runtime (no socket, no fs except a temp dir). Time and memory limits.
- 4.If the task is arithmetic, a calc tool is safer than exec.
Learn elsewhere
- →Tool Permissions
- →Tool Validation
Real Example
Scenario
Model writes a pandas snippet to average 20 numbers. Sandbox returns 14.2. It cannot import requests.
What you would do
In Tool Calling & Function Calling, apply Python Tool to this scenario: Model writes a pandas snippet to average 20 numbers. Identify the inputs, run the technique, validate the output, and note one thing you would monitor in production.
Commands
Commands to Remember
Sandbox or do not shipNo network, no secretsCaps on time/memoryCalc tool if you only need math
Cheat Sheet
Quick recap
quick ref- •Lab behind glass
- •Exec is power
- •Lock network
- •Small outputs
Common Mistakes
- ✕eval() in the API process
- ✕Allowing pip install from the tool
- ✕Returning a 400-line traceback to the model
