Documentation Index
Fetch the complete documentation index at: https://mintlify.com/alibaba/OpenSandbox/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The OpenSandbox Server is a production-grade, FastAPI-based service that acts as the control plane for managing the lifecycle of containerized sandboxes. It provides standardized REST interfaces for creating, running, monitoring, and disposing of isolated execution environments across container platforms.Core Capabilities
Lifecycle APIs
Standardized REST interfaces for complete sandbox management:- Create and provision sandboxes
- Start, pause, and resume operations
- Delete and cleanup
- Status monitoring with transition tracking
Pluggable Runtimes
Docker
Production-ready runtime for local and single-host deployments
Kubernetes
Distributed runtime for cluster deployments (see
kubernetes/ directory)Networking Modes
Host Mode: Containers share the host network for maximum performance. Only one sandbox instance at a time. Bridge Mode: Isolated container networking with built-in HTTP routing support.Access Control
API Key authentication viaOPEN-SANDBOX-API-KEY header. Can be disabled for local/dev environments.
Resource Management
- Resource quotas: CPU/memory limits with Kubernetes-style specs (e.g.,
500m,512Mi) - Automatic expiration: Configurable TTL with renewal support
- Registry support: Public and private container images
Extended Features
- Async provisioning: Background creation to reduce API latency
- Timer restoration: Expiration timers restored after server restart
- Environment injection: Per-sandbox environment variables and metadata
- Port resolution: Dynamic endpoint generation for service access
- Structured errors: Standard error codes and messages
Requirements
- Python: 3.10 or higher
- Package Manager: uv (recommended) or pip
- Runtime Backend:
- Docker Engine 20.10+ (for Docker runtime)
- Kubernetes 1.21+ (for Kubernetes runtime)
- Operating System: Linux, macOS, or Windows with WSL2
Installation
Install from PyPI:For source development or contributions, clone the repo and run
uv sync inside server/.Configuration
The server uses a TOML configuration file to select and configure the underlying runtime.Initialize Configuration
Create a configuration file from a template:Docker Runtime Examples
- Host Networking
- Bridge Networking
- Security Hardening
Further reading: Docker container security
Ingress Configuration
- wildcard:
<sandbox-id>-<port>.example.com/path/to/request - uri:
10.0.0.1:8000/<sandbox-id>/<port>/path/to/request - header:
gateway.example.comwith headerOpenSandbox-Ingress-To: <sandbox-id>-<port>
Kubernetes Runtime
Egress Configuration
Required when usingnetworkPolicy in sandbox creation requests:
- Only supported in Docker bridge mode
- Requests with
networkPolicyare rejected whennetwork_mode=hostoregress.imageis not configured - Main container shares the sidecar netns and drops
NET_ADMIN - IPv6 is disabled when egress sidecar is injected
Running the Server
Start the server using the installed CLI:http://0.0.0.0:8080 (or your configured host/port).
Health Check
API Documentation
Once running, interactive API documentation is available:- Swagger UI: http://localhost:8080/docs
- ReDoc: http://localhost:8080/redoc
Authentication
Authentication is enforced only whenserver.api_key is set. All endpoints except /health, /docs, /redoc require the OPEN-SANDBOX-API-KEY header:
Example Usage
Create a Sandbox
Get Sandbox Details
Get Service Endpoint
Renew Expiration
Delete a Sandbox
Architecture
Component Responsibilities
- API Layer (
src/api/): HTTP request handling, validation, and response formatting - Service Layer (
src/services/): Business logic for sandbox lifecycle operations - Middleware (
src/middleware/): Cross-cutting concerns (authentication, logging) - Configuration (
src/config.py): Centralized configuration management - Runtime Implementations: Platform-specific sandbox orchestration
Sandbox Lifecycle States
State Transitions:- Pending: Container is starting
- Running: Sandbox is active and ready
- Paused: Execution paused, resources held
- Stopping: Cleanup in progress
- Terminated: Successfully stopped
- Failed: Error during lifecycle
Configuration Reference
Server Configuration
| Key | Type | Default | Description |
|---|---|---|---|
server.host | string | "0.0.0.0" | Interface to bind |
server.port | integer | 8080 | Port to listen on |
server.log_level | string | "INFO" | Python logging level |
server.api_key | string | null | API key for authentication |
Runtime Configuration
| Key | Type | Required | Description |
|---|---|---|---|
runtime.type | string | Yes | "docker" or "kubernetes" |
runtime.execd_image | string | Yes | Container image with execd binary |
Egress Configuration
| Key | Type | Required | Description |
|---|---|---|---|
egress.image | string | When using networkPolicy | Container image with egress binary |
Docker Configuration
| Key | Type | Default | Description |
|---|---|---|---|
docker.network_mode | string | "host" | "host" or "bridge" |
Environment Variables
| Variable | Description |
|---|---|
SANDBOX_CONFIG_PATH | Override config file location |
DOCKER_HOST | Docker daemon URL (e.g., unix:///var/run/docker.sock) |
PENDING_FAILURE_TTL | TTL for failed pending sandboxes in seconds (default: 3600) |
Development
Code Quality
Testing
Support
- Documentation: See
DEVELOPMENT.mdfor development guidance - Issues: Report defects via GitHub Issues
- Discussions: Use GitHub Discussions for Q&A and ideas