Skip to main content

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 via OPEN-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

Further reading: Docker container security

Ingress Configuration

Gateway Mode (Kubernetes only):
Routing mode examples:
  • wildcard: <sandbox-id>-<port>.example.com/path/to/request
  • uri: 10.0.0.1:8000/<sandbox-id>/<port>/path/to/request
  • header: gateway.example.com with header OpenSandbox-Ingress-To: <sandbox-id>-<port>

Kubernetes Runtime

Informer settings are beta and enabled by default to reduce API calls. Set informer_enabled = false to turn off.

Egress Configuration

Required when using networkPolicy in sandbox creation requests:
  • Only supported in Docker bridge mode
  • Requests with networkPolicy are rejected when network_mode=host or egress.image is not configured
  • Main container shares the sidecar netns and drops NET_ADMIN
  • IPv6 is disabled when egress sidecar is injected
Example request with network policy:

Running the Server

Start the server using the installed CLI:
Or specify a custom config path:
The server will start at http://0.0.0.0:8080 (or your configured host/port).

Health Check

Expected response:

API Documentation

Once running, interactive API documentation is available:

Authentication

Authentication is enforced only when server.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

Runtime Configuration

Egress Configuration

Docker Configuration

Environment Variables

Development

Code Quality

Testing

Support

  • Documentation: See DEVELOPMENT.md for development guidance
  • Issues: Report defects via GitHub Issues
  • Discussions: Use GitHub Discussions for Q&A and ideas