Overview
Execute Python code in a secure sandboxed environment directly from chat. The sandbox runs on Vercel infrastructure with a 5-minute timeout and 2 vCPUs.Quick Start
Enable code execution inchat.config.ts:
Pre-installed Packages
The following packages are available out of the box:matplotlib- Plotting and visualizationpandas- Data analysisnumpy- Numerical computingsympy- Symbolic mathematicsyfinance- Yahoo Finance market data
Installing Additional Packages
Add!pip install lines at the top of your code. They are automatically stripped before execution:
Output
There are two ways to return output: 1. Useprint()
result or results
The sandbox automatically prints these variables if they exist:
Charts
The sandbox supportsmatplotlib charts. No need to call plt.show(). The chart is saved automatically:
- Line charts
- Scatter plots
- Bar charts
Charts are rendered as PNG images. Complex chart types beyond line, scatter, and bar may not render correctly.
Customization
Sandbox Runtime
Set the Python version via environment variable:Non-Vercel Deployments
When deploying outside Vercel (Docker, Railway, Fly.io, etc.), you need to authenticate with an access token sinceVERCEL_OIDC_TOKEN is unavailable.
- Copy your Team ID from team settings
- Copy your Project ID from project settings
- Create a token in your Vercel account settings scoped to your team
- Set these environment variables:
Tool Definition
The tool is defined inlib/ai/tools/code-execution.ts. You can modify the description to adjust how the AI uses it, or change the base packages installed in the sandbox.