Skip to main content

Overview

Daytona’s architecture is designed for massive parallelization, sub-90ms sandbox creation, and secure isolation of AI-generated code execution. The system consists of four primary components that work together to provide a complete platform for running code in isolated environments.

System Architecture

The Daytona platform follows a distributed architecture with clear separation of concerns:

Core Components

API Server

The API Server is the primary entry point for all client interactions. Responsibilities:
  • Authenticate and authorize requests
  • Manage sandbox lifecycle operations
  • Coordinate snapshot and volume management
  • Route requests to appropriate runners
  • Handle WebSocket connections for real-time updates
Key Features:
  • RESTful HTTP API
  • WebSocket support for live logs and events
  • TLS/HTTPS support
  • Token-based authentication
  • Rate limiting and quota management
Technology:
  • Built with TypeScript/Node.js
  • Runs as a stateless service
  • Horizontally scalable

Runner

The Runner is the execution engine that manages Docker containers and sandbox lifecycle on compute nodes. Responsibilities:
  • Create and manage Docker containers for sandboxes
  • Handle snapshot building and pulling
  • Manage volume mounting and unmounting
  • Enforce resource quotas (CPU, memory, GPU, disk)
  • Monitor container health and state
  • Implement network isolation rules
  • Collect metrics and telemetry
Key Features:
  • Docker container orchestration
  • Resource limits enforcement
  • Network policy management with iptables
  • Volume cleanup and maintenance
  • Snapshot caching for fast startup
  • State synchronization with API
Technology:
  • Built with Go
  • Interfaces with Docker Engine API
  • Manages iptables for network isolation
  • Integrates with S3 for volume storage
Architecture:
Services:
Manages all Docker operations:
  • Container creation and lifecycle
  • Image pulling and caching
  • Volume mounting via S3
  • Resource limit configuration
  • Network namespace setup
Enforces network isolation:
  • Creates iptables rules per sandbox
  • Implements allow/deny lists
  • Blocks network access when required
  • Cleans up rules on sandbox deletion
Monitors sandbox resources:
  • CPU usage tracking
  • Memory consumption
  • Disk I/O metrics
  • Network bandwidth
  • GPU utilization
Synchronizes sandbox state:
  • Polls Docker for container status
  • Updates API with current states
  • Handles state transitions
  • Detects and reports errors

Daemon

The Daemon runs inside each sandbox container and provides the execution environment. Responsibilities:
  • Execute user code and commands
  • Provide file system access
  • Handle SSH connections
  • Manage terminal sessions
  • Support Language Server Protocol (LSP)
  • Execute entrypoint commands
  • Graceful shutdown handling
Key Features:
  • Toolbox server for code execution and file operations
  • SSH server on port 22
  • Terminal server on port 22222
  • LSP server for code intelligence
  • Process management and monitoring
  • Session recording support
Technology:
  • Built with Go
  • Statically compiled binary injected into containers
  • Minimal resource footprint
  • Supports graceful termination
Services:
Provides programmatic access:
  • Code execution API
  • File system operations (read, write, delete)
  • Git operations
  • LSP integration
  • Process management
  • Environment variable access
Enables secure shell access:
  • Key-based authentication
  • Interactive shell sessions
  • SCP/SFTP file transfer
  • Port forwarding
Supports browser-based terminals:
  • WebSocket-based communication
  • Multiple concurrent sessions
  • TTY emulation
  • Session recording

Proxy

The Proxy routes HTTP/WebSocket traffic to sandbox daemons for file operations and code execution. Responsibilities:
  • Route requests to specific sandbox instances
  • Load balance across multiple sandbox connections
  • Handle WebSocket upgrades for real-time communication
  • Manage connection pooling
  • Support build logs streaming
Key Features:
  • Dynamic routing based on sandbox ID
  • WebSocket support for bidirectional communication
  • Connection health monitoring
  • Automatic failover
  • TLS termination
Technology:
  • Built with Go
  • Reverse proxy implementation
  • Supports both HTTP and WebSocket protocols
Routing:

Data Flow

Sandbox Creation Flow

Code Execution Flow

Volume Mounting Flow

Network Architecture

Network Isolation

Each sandbox runs in an isolated network namespace:
Network Rules Manager creates iptables rules:

Port Mapping

Resource Management

Resource Limits

Runner enforces resource quotas using Docker:

Metrics Collection

Storage Architecture

Snapshot Storage

Volume Storage

Scaling and Distribution

Horizontal Scaling

API Server:
  • Stateless design allows multiple instances
  • Load balanced via standard HTTP load balancers
  • Shared database for state persistence
Runner:
  • Each runner manages a pool of compute resources
  • Sandboxes distributed across runners
  • Runners register with API on startup
  • Automatic failover on runner failure
Proxy:
  • Routes to sandboxes on any runner
  • Maintains connection pool per sandbox
  • Can be horizontally scaled

Geographic Distribution

High Availability

Component Redundancy

  • API Server: Multiple instances behind load balancer
  • Runners: Multiple runners per region
  • Storage: S3 provides built-in redundancy
  • Snapshots: Replicated across regions

Failure Handling

Sandbox Failure:
  • Detected by Docker monitor
  • State updated to “error”
  • Error reason captured and reported
  • User notified via webhook/API
Runner Failure:
  • Sandboxes on failed runner marked as “unknown”
  • New sandboxes routed to healthy runners
  • Failed runner’s sandboxes can be recreated
Network Partition:
  • Sandbox continues running on runner
  • State sync resumes when connectivity restored
  • Sandboxes not lost during brief outages

Performance Optimizations

Snapshot Caching

Connection Pooling

Resource Cleanup

Monitoring and Observability

Telemetry

Daytona integrates with OpenTelemetry:

Logging

Structured logging throughout the system:

Security Architecture

See Security for detailed security architecture.

Next Steps

Security

Learn about isolation and security model

Sandboxes

Understand sandbox lifecycle and operations

API Reference

Explore the complete API

Self-Hosting

Deploy Daytona in your infrastructure