Execute commands and stream output. Includes exec(), execStream(), and background process management.
API Reference
The Sandbox SDK provides a comprehensive API for executing code, managing files, running processes, and exposing services in isolated sandboxes. All operations are performed through the Sandbox instance you obtain via getSandbox().
import { getSandbox } from '@cloudflare/sandbox';
const sandbox = getSandbox(env.Sandbox, 'user-123');The same sandbox ID will always return the same sandbox instance. You can architect your application to use a single sandbox ID for multiple users, or use unique IDs per user or session. Using unique sandbox IDs per user is recommended if you are providing code generation or execution capabilities directly to your users.
The Sandbox SDK is organized into focused APIs:
Read, write, and manage files in the sandbox filesystem. Includes directory operations and file metadata.
Execute Python and JavaScript code with rich outputs including charts, tables, and formatted data.
Expose services running in the sandbox via preview URLs. Access web servers and APIs from the internet.
Advanced: Create isolated execution contexts with persistent shell state. Configure environment variables and manage container lifecycle.
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark