Overview
The Code Interpreter capability allows AI models to write and execute Python code in a secure sandboxed environment. This enables data analysis, mathematical computations, file processing, and more.How It Works
When enabled, the AI can:- Write and execute Python code
- Process uploaded files (CSV, JSON, images, etc.)
- Generate visualizations and charts
- Perform complex calculations
- Analyze data and return results
Setup
Get API Key
Obtain a code interpreter API key from code.librechat.ai or configure your own service.
Using Code Interpreter
In Agents
Example Prompts
- Data Analysis
- Visualization
- Math & Computation
- File Processing
File Upload Support
Code Interpreter can work with uploaded files:Supported File Types
Supported File Types
- Data: CSV, JSON, Excel (.xlsx), TSV
- Text: TXT, MD, PDF
- Images: PNG, JPG, GIF (for analysis)
- Code: Python (.py), Jupyter notebooks (.ipynb)
Files are processed in the execution environment. Maximum file size depends on your configuration.
Configuration Options
Agent-Level Settings
Configure code execution for specific agents:System-Level Settings
Configure globally inlibrechat.yaml:
Authentication Types
Code Interpreter supports different authentication methods:- System-Provided
- User-Provided
Admin configures a shared API key:All users can execute code without individual keys.
Code Execution Flow
Security
Code execution happens in a sandboxed environment with:
- Isolated processes: Each execution runs separately
- Timeout limits: Prevents infinite loops
- Resource constraints: Memory and CPU limits
- No network access: (Default) Sandbox cannot make external requests
Limitations
- Timeout: Code execution has time limits (typically 60 seconds)
- Package restrictions: Only pre-installed Python packages are available
- No persistence: Environment resets between executions
- File size limits: Large files may exceed processing limits
API Key Dialog
When using user-provided authentication, a dialog allows key management:Troubleshooting
Code execution fails
Code execution fails
- Verify
LIBRECHAT_CODE_API_KEYis set correctly - Check API key validity at code.librechat.ai
- Ensure the code interpreter service is reachable
Timeout errors
Timeout errors
- Simplify complex operations
- Break large tasks into smaller steps
- Optimize code for performance
Import errors
Import errors
- Check which packages are pre-installed in the sandbox
- Use standard library modules when possible
- Contact admin to add custom packages