简体中文 · Architecture · Platform Design
OpenSandbox is a lightweight sandbox data-plane service built with .NET 10 / 11 and the native Docker Engine API. It provides a unified HTTP/WebSocket API, cross-platform PTY terminals, dynamic port & wildcard subdomain preview routing, container security hardening, and a multi-target .NET SDK.
This repository includes:
src/OpenSandbox.Abstractions: dependency-free core abstractions (ISandboxRuntime,ISandboxStore), domain models, and typed exceptionssrc/OpenSandbox.Contracts: dependency-free shared HTTP API DTOssrc/OpenSandbox.Runtime.Docker: native Docker Engine REST API runtime (Unix socket / Named pipe / TCP, auto image pull, container hardening, host volume allowlist, dynamic container-IP port resolution, cross-platform hijacked PTY + resize, in-memory TAR file I/O, multiplexed stdout/stderr logs, and Docker Events streaming)src/OpenSandbox.Store.FileSystem: cached, atomic JSON metadata storesrc/OpenSandbox.Server: ASP.NET Core Minimal API & YARP reverse-proxy data-plane server (path-prefix and wildcard subdomain preview, constant-time API key/Bearer auth, global error mapping, event-driven state sync, expiration cleanup)src/OpenSandbox.ControlPlane: multi-tenant, multi-node platform control plane (node registry &Filter -> Scorescheduler, generic parameterized templates with remote file injection, template warm pools, container snapshots, multi-node wildcard subdomain preview gateway with auto-wake, tenant quotas, scoped RBAC API keys + OIDC SSO, audit logging, SQLite/PostgreSQL persistence, Prometheus/metrics)web: React 19 + TypeScript + Vite + Tailwind CSS v4 management console SPA (hosted automatically byOpenSandbox.ControlPlanewhen built)deploy: one-command Docker Compose stack (ControlPlane+Server+PostgreSQL 17+Prometheus)sdks/dotnet/OpenSandbox.Sdk: multi-target .NET SDK (netstandard2.1;net8.0;net10.0;net11.0)samples/dotnet/OpenSandbox.Sample: runnable SDK sampletests/OpenSandbox.Sdk.Tests,tests/OpenSandbox.Server.Tests,tests/OpenSandbox.ControlPlane.Tests: Docker-free xUnit test suites
See docs/ARCHITECTURE.md for the layered architecture and docs/PLATFORM_DESIGN.md for the control-plane design (multi-node scheduling, generic templates, subdomain preview, and multi-tenant governance).
Core endpoints exposed by OpenSandbox.Server:
- Health & observability:
GET /health,GET /metrics(Prometheus text format),GET /v1/ping - Sandbox lifecycle:
GET /v1/sandboxes,POST /v1/sandboxes,GET /v1/sandboxes/{id},DELETE /v1/sandboxes/{id} - State & expiration:
POST /v1/sandboxes/{id}/pause,POST /v1/sandboxes/{id}/resume,POST /v1/sandboxes/{id}/restart,POST /v1/sandboxes/{id}/renew-expiration - Execution & telemetry:
GET /v1/sandboxes/{id}/stats,GET /v1/sandboxes/{id}/logs,POST /v1/sandboxes/{id}/exec(supportsworkingDirectory,env,timeoutSeconds,user),POST /v1/sandboxes/{id}/exec/stream(SSE real-time stdout/stderr/exit streaming) - File management:
GET/DELETE /v1/sandboxes/{id}/files,GET/POST /v1/sandboxes/{id}/files/content,GET/PUT /v1/sandboxes/{id}/files/raw(binary upload/download without Base64 overhead),POST /v1/sandboxes/{id}/files/search(glob/grep),POST /v1/sandboxes/{id}/directories,POST /v1/sandboxes/{id}/files/move,POST /v1/sandboxes/{id}/files/copy - Networking & streams:
GET /v1/sandboxes/{id}/endpoints/{port},/v1/sandboxes/{id}/proxy/{port}/..., wildcard subdomain preview ({port}-{id}.{SubdomainBaseDomain}),/v1/sandboxes/{id}/terminal/ws(true PTY + resize),/v1/sandboxes/{id}/logs/ws - Network isolation & egress policy:
networkPolicy.defaultAction(Allow/Deny/Internalwith optional per-sandbox isolated internal networks),egressRules(ordered domain/wildcard/CIDR allow/deny rules), and cloud metadata SSRF blocking (blockCloudMetadata)
- Multi-node registry & two-phase scheduler (
LeastAllocated/BinPacking+NodeSelector+ region affinity) - Generic parameterized template registry with remote file injection (zero host filesystem coupling)
- Multi-node wildcard subdomain preview gateway with automatic idle-instance wake (
AutoWakePausedInstances) - Multi-tenant governance: quotas, idle auto-pause & auto-expiration sweeps, scoped RBAC API keys + optional OIDC/JWT Bearer SSO, audit logs, SQLite or PostgreSQL persistence, and Prometheus
/metrics
.NET SDK 11.0+(seeglobal.json)- A running Docker daemon accessible via Unix socket (
/var/run/docker.sock), Windows named pipe, orDOCKER_HOST(required for sandbox operations, not for building/testing — nodockerCLI binary required)
dotnet run --project src/OpenSandbox.Server -f net11.0Default dev URL (launchSettings.json): http://localhost:5237
- OpenAPI document:
http://localhost:5237/openapi/v1.json - Health check:
http://localhost:5237/health
| Key | Default | Description |
|---|---|---|
Tokens |
['dev-sandbox-key'] |
Allowed API keys or bearer tokens (empty disables /v1/* auth) |
CleanupIntervalSeconds |
30 |
Interval for cleaning up expired sandboxes |
ProxyUpstreamHost |
127.0.0.1 |
Upstream host used when forwarding to host-published ports |
EndpointHost |
null |
Optional host override for direct endpoint URLs |
EnableEventSync |
true |
Enables startup container reconciliation and live Docker Events state sync |
Proxy.ActivityTimeoutMinutes |
10 |
Activity timeout for proxied requests |
Proxy.SignedUrlLifetimeMinutes |
10 |
Sliding expiration window for signed proxy URLs and cookies |
Proxy.SignedUrlSecret |
null |
HMAC signing secret (falls back to the first configured token) |
Proxy.SubdomainBaseDomain |
null |
Optional wildcard domain for {port}-{id}.{domain} subdomain preview routing |
Proxy.SubdomainScheme |
null |
Optional scheme override (http / https) for subdomain preview URLs |
| Key | Default | Description |
|---|---|---|
Endpoint |
null |
Docker Engine URI (unix://, npipe://, tcp://, http://). Falls back to DOCKER_HOST then platform default |
ApiVersion |
v1.43 |
Docker Engine REST API version prefix |
ProxyResolutionMode |
Auto |
Auto (published port first, then container IP for dynamic ports), ContainerIp, or PublishedPort |
InternalNetworkName |
opensandbox-internal |
Shared Docker --internal network name for Internal network policy |
MaxFileSizeBytes |
52428800 |
Maximum allowed file size (50 MiB) for read/write file APIs |
AllowedHostVolumeRoots |
[] |
Allowlist of host directories permitted for bind mounts (empty denies host mounts) |
AllowUnrestrictedHostVolumes |
false |
Explicit opt-in to disable host volume allowlist checks |
PublishedPorts |
80, 443, 3000, ... |
Ports pre-published to random host ports on container creation |
Security.DropAllCapabilities |
true |
Drops all Linux capabilities (CapDrop: ["ALL"]) |
Security.NoNewPrivileges |
true |
Adds no-new-privileges:true |
Security.PidsLimit |
256 |
Max container PIDs to mitigate fork bombs |
Security.DisableSwap |
true |
Pins MemorySwap equal to Memory when a memory limit is set |
Security.ReadonlyRootfs |
false |
Mounts container rootfs read-only when enabled |
Security.Runtime |
null |
Optional OCI runtime override (e.g. runsc, kata-runtime) |
Security.DefaultUser |
null |
Optional default container user (e.g. 1000:1000) |
| Key | Default | Description |
|---|---|---|
StorePath |
data/sandboxes.json |
Path of the sandbox metadata store file |
dotnet build OpenSandbox.slnx
dotnet test OpenSandbox.slnx
dotnet run --project samples/dotnet/OpenSandbox.Sample -f net11.0See LICENSE.