Related
- CLI Code Execution - Execute code from CLI
What You’ll Learn
- How to execute code synchronously and asynchronously
- How to capture rich outputs (plots, DataFrames, visualizations)
- How to run code in the background for long-running tasks
- How to stream execution results in real-time
- How to manage processes and handle async webhooks
Code Execution Overview
| Execution Mode | SDK Method | API Endpoint |
|---|---|---|
| Synchronous | sandbox.run_code() | POST /execute |
| Rich Output | sandbox.run_code() with rich_output | POST /execute |
| Background | sandbox.run_code_background() | POST /execute/background |
| Streaming | sandbox.run_code_stream() | POST /execute/stream |
| Process Management | sandbox.list_processes() | GET /processes |
| Async Webhooks | Webhook configuration | Webhook endpoints |
Core Concepts
Synchronous Execution
Execute code and wait for results. Perfect for quick scripts and data analysis.- Synchronous Execution - Execute code and get results immediately
- SDK: Python: sandbox.run_code() | JavaScript: sandbox.runCode()
- API: POST /execute
Rich Output Capture
Capture matplotlib plots, pandas DataFrames, and other rich outputs automatically.- Rich Output - Capture plots, DataFrames, and visualizations
- SDK: Python: sandbox.run_code() with rich_output | JavaScript: sandbox.runCode() with richOutput
- API: POST /execute with
rich_outputparameter
Background Execution
Run long-running code without blocking. Perfect for training models or processing large datasets.- Background Execution - Run code asynchronously
- SDK: Python: sandbox.run_code_background() | JavaScript: sandbox.runCodeBackground()
- API: POST /execute/background
Streaming Execution
Stream execution results in real-time as code runs.- Streaming Execution - Stream results in real-time
- SDK: Python: sandbox.run_code_stream() | JavaScript: sandbox.runCodeStream()
- API: POST /execute/stream
Process Management
List, monitor, and manage background processes.- Process Management - Manage background processes
- SDK: Python: sandbox.list_processes() | JavaScript: sandbox.listProcesses()
- API: GET /processes | DELETE /execute/kill
Async Webhooks
Handle code execution results via webhooks for async workflows.- Async Webhooks - Handle results via webhooks
- SDK: Webhook configuration in SDK | API: Webhook endpoints
SDK Reference
Python SDK
Complete reference for Python code execution.- Sandbox.run_code() - Synchronous execution
- Sandbox.run_code_background() - Background execution
- Sandbox.run_code_stream() - Streaming execution
- Sandbox.list_processes() - Process management
JavaScript SDK
Complete reference for JavaScript/TypeScript code execution.- Sandbox.runCode() - Synchronous execution
- Sandbox.runCodeBackground() - Background execution
- Sandbox.runCodeStream() - Streaming execution
- Sandbox.listProcesses() - Process management
API Reference
VM Agent API
REST API endpoints for code execution.- VM Agent API Overview - API overview
- Execute Code -
POST /execute- Synchronous execution - Execute Background -
POST /execute/background- Background execution - Execute Async -
POST /execute/async- Async execution - List Processes -
GET /processes- List background processes - Kill Process -
DELETE /execute/kill- Terminate process
Quick Start
If you’re new to code execution, start here:- Synchronous Execution - Execute your first code
- Rich Output - Capture plots and DataFrames
- Background Execution - Run long-running tasks
Related Topics
- Sandboxes - Create and manage sandboxes
- File Operations - Work with files during execution
- Environment Variables - Configure execution environment
- Observability - Monitor execution metrics
Next Steps
- Learn about File Operations for working with files
- Explore Environment Variables for configuration
- Review Process Management for advanced workflows
- Check out Observability for monitoring

