Agents can execute Python code directly in their sandboxed workspace. This is ideal for data processing, calculations, file parsing, and any task that benefits from Python's libraries and expressiveness.
What you can ask agents to do
- "Parse this JSON file and extract all email addresses"
- "Calculate the average, median, and standard deviation of this dataset"
- "Read the CSV I uploaded and create a summary with charts"
- "Write a Python script to clean up this data and save the result"
- "Convert this XML file to JSON"
How it works
When an agent runs Python code:
- The code executes with
python3in the agent's workspace directory - Standard output and errors are captured
- The result is returned to the agent for use in its response
The agent can read workspace files, process them with Python, and produce new files as output.
What's available
The Python environment includes the standard library. Agents can install additional packages using pip via the shell tool when needed:
- "Install pandas and then process this CSV"
- "Use matplotlib to create a chart from this data"
Sandbox
All Python code runs inside the agent's sandbox. The sandbox controls which files the agent can access, which network destinations it can reach, and how long scripts can run. You configure these restrictions per agent in the agent settings.
When to use Python vs. other tools
| Scenario | Best tool |
|---|---|
| Data processing and analysis | Python |
| File parsing (CSV, JSON, XML) | Python |
| Math, statistics, calculations | Python |
| Data visualization | Python (with matplotlib/plotly) |
| System commands (ls, curl, git) | Shell |
| Installing packages | Shell |
| API integrations, async tasks | Node.js |
Tips
- Upload data files first. Upload your CSV, JSON, or other data files in the chat, then ask the agent to process them with Python.
- Ask for files as output. "Process this data and save the result as a CSV I can download" produces a downloadable file.
- Agents can chain steps. "Install pandas, load the data, clean it, and create a summary report" all happens in sequence.
Next steps
- Running Shell Commands. For system commands and package management.
- Running Node.js Code. For JavaScript execution.
- Working with Files. How agents handle file uploads and downloads.