Skip to content

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:

  1. The code executes with python3 in the agent's workspace directory
  2. Standard output and errors are captured
  3. 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

ScenarioBest tool
Data processing and analysisPython
File parsing (CSV, JSON, XML)Python
Math, statistics, calculationsPython
Data visualizationPython (with matplotlib/plotly)
System commands (ls, curl, git)Shell
Installing packagesShell
API integrations, async tasksNode.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