Code Execution
π Python Code Execution Sandbox
Code Execution enables your AI agent to write and run Python code in a secure, isolated sandbox environment. This powerful capability allows agents to perform complex data analysis, mathematical computations, file processing, and system operations that go beyond simple text generation.
Prerequisites
Before enabling code execution:
PixelML Connection Required: You must add a PixelML connection in your workspace connections
Credit-Based Usage: Code execution consumes credits based on session runtime
Usage Tracking: Charges are calculated per second of active code session time
To set up:
Navigate to Workspace Settings β Connections
Add a new PixelML connection with your API key
Credits are automatically deducted during code execution sessions
π§ What Is Code Execution?
Code Execution provides your AI agent with four specialized tools:
Execute Python Code: Run Python scripts in a persistent sandbox environment
Upload Files to Sandbox: Transfer files from Drive storage to the code execution environment
Download Files from Sandbox: Save generated files back to Drive storage
Execute Shell Commands: Run system commands for package installation and file operations
Combining Code Execution with Skills
When you enable both Code Execution and Skills for your agent, you unlock a powerful capability: your agent can read code examples and templates from Skills, then execute them in the sandbox.
This combination is inspired by Anthropic's Claude Skills with Code Executionβwhere skills provide procedural knowledge and code templates, while code execution enables the agent to run and adapt those templates for your specific tasks.
How It Works:
Agent discovers relevant skill using the skill browser tool
Agent reads code templates or examples from the skill using skill reader
Agent adapts the code to your specific requirements
Agent executes the adapted code in the sandbox using code execution
Agent delivers results or saves outputs to Drive
Example Workflow:
Benefits of This Combination:
β Standardized implementations: Agent follows proven patterns from Skills
β Repeatable workflows: Same skill templates work across different datasets
β Best practices built-in: Skills encode expert knowledge and error handling
β Faster execution: Agent doesn't need to write code from scratch
β Organization consistency: All agents use the same approved code patterns
To Enable This Capability:
Navigate to Tab 5: Skills & Capabilities and add relevant skills (see Skills documentation)
Navigate to Tab 6: Code Execution and toggle ON
Ensure PixelML connection is configured in workspace settings
Your agent can now read Skills and execute code from them
π‘ Key Capabilities
Data Analysis & Processing
Mathematical Computations
Image Processing
File Format Conversions
Web Data Fetching
ποΈ How Code Execution Works
Session Lifecycle Architecture
Each agent turn (response to a user message) gets its own isolated sandbox session:
Key Characteristics:
Turn-Based Sessions: Each agent response gets a fresh sandbox session
Intra-Turn Persistence: Variables, imports, and files persist during a single agent turn
Session Isolation: Each turn gets its own independent sandbox environment
Automatic Cleanup: Sessions are terminated when the agent completes its response
State Reset: The next agent turn starts with a completely fresh environment
On-Demand Creation: Sessions are only created when the agent needs to execute code
Important: Unlike a persistent conversation-wide session, you cannot reference variables or files from previous agent responses. Each turn is completely isolated.
Example: Multi-Step Analysis Within a Single Turn
Important Note: All three steps must happen in the same agent response. If the agent completes its response after Step 1, the next turn will have a fresh session where df is no longer available.
π File Transfer System
Upload Files to Sandbox
Transfer files from Drive storage to the sandbox for processing:
Supported File Types:
Text Files:
.txt,.md,.py,.js,.json,.csv,.xml,.html,.css,.yaml,.sql, etc.Images:
.jpg,.jpeg,.png,.gif,.bmp,.webp,.svgDocuments:
.pdfMedia:
.mp4,.mp3,.wav,.flac,.ogg,.avi,.mov
Download Files from Sandbox
Save generated files back to Drive storage:
Important Notes:
Files in the sandbox are temporary and deleted when the agent turn ends
Always download important results to Drive for persistence across turns
Set
"replace": Trueto overwrite existing files in DriveDefault behavior prevents accidental overwrites
Files uploaded in one turn will NOT be available in the next turn's session
β‘ Shell Command Execution
Package Installation
Install Python packages as needed:
Important: Packages are lost when the session ends. Since each agent turn starts a fresh session, packages must be reinstalled if needed in subsequent turns.
System Operations
Perform file and system operations:
π Security & Isolation
Sandbox Isolation Features
File Type Restrictions
Only safe file types are allowed for upload/download:
Resource Quotas
Cost & Credit Management
Requirement: A valid PixelML connection must be configured in Workspace Settings β Connections before code execution can be used.
π Common Use Cases
1. Data Analysis Agent
Example Conversation:
2. Image Processing Agent
3. Report Generation Agent
4. Data Transformation Agent
5. Scientific Computing Agent
6. Skills + Code Execution Agent
Scenario: Agent with both Skills and Code Execution enabled
Example Conversation:
Key Advantages:
Consistency: Same proven code pattern used every time
Speed: No need to design analysis from scratch
Quality: Skills contain tested, optimized implementations
Governance: Organization controls which code patterns are available
Learning: New team members see best practices in action
π― Best Practices
Session Management
File Management
Error Handling
Performance Optimization
Skills + Code Execution Best Practices
When using Skills with Code Execution enabled:
Skill Template Design Tips:
π¨ Common Issues & Solutions
Package Not Found
File Not Found
Session State Lost
Timeout Errors
File Download Conflicts
π Advanced Patterns
Iterative Data Processing
Multi-Format Output
Combining Internet Data with Drive Files
π Learning Resources
Essential Python Libraries
Code Execution Examples
β
Code Execution Checklist
Before deploying your agent with code execution:
Core Setup
Execution Design
Security & Compliance
Skills Integration (if using Skills + Code Execution)
Code execution transforms your agent from a conversational assistant into a powerful computational engine capable of data analysis, file processing, and complex problem-solving.
Last updated
Was this helpful?