Overview
The OpenSandbox Ingress is an HTTP/WebSocket reverse proxy that routes external traffic to sandbox instances running in a Kubernetes cluster. It watches sandbox Custom Resources (CRs) and dynamically routes requests based on sandbox IDs and ports.Key Features
- Dynamic routing: Routes to sandbox instances based on CR annotations or status
- Multi-provider support: Works with BatchSandbox or AgentSandbox resources
- WebSocket support: Full bidirectional WebSocket proxying
- Health checks: Built-in
/status.okendpoint - Flexible routing modes: Header-based or URI path-based routing
Architecture
Component Discovery
The ingress watches sandbox CRs in a target namespace:- BatchSandbox
- AgentSandbox
Reads endpoints from
sandbox.opensandbox.io/endpoints annotation:Routing Modes
The ingress supports two routing modes for discovering sandbox instances.Header Mode (default)
Routes requests based on theOpenSandbox-Ingress-To header or the Host header.
Format:
- Header:
OpenSandbox-Ingress-To: <sandbox-id>-<port> - Host:
<sandbox-id>-<port>.<domain>
- Extracts sandbox ID and port from the format
<sandbox-id>-<port> - The last segment after the last
-is treated as the port - Everything before the last
-is treated as the sandbox ID - The original request path is preserved and forwarded
URI Mode
Routes requests based on the URI path structure. Format:/<sandbox-id>/<sandbox-port>/<path-to-request>
Example:
- First path segment: sandbox ID
- Second path segment: sandbox port
- Remaining path: forwarded to the target sandbox as the request URI
- If no remaining path is provided, defaults to
/
- When you cannot modify HTTP headers
- When you need path-based routing
- For simpler client configuration without custom headers
Quick Start
/- Proxy endpoint/status.ok- Health check
Configuration
Command-line Flags
| Flag | Type | Default | Description |
|---|---|---|---|
--namespace | string | Required | Target Kubernetes namespace to watch |
--provider-type | string | batchsandbox | batchsandbox or agent-sandbox |
--mode | string | header | Routing mode: header or uri |
--port | int | 28888 | HTTP listen port |
--log-level | string | info | Log level: debug, info, warn, error |
Environment Variables
Build
Local Build
Docker Build
Multi-arch Build
Use the provided build script for linux/amd64 and linux/arm64:Deployment
Kubernetes Deployment
RBAC Configuration
Runtime Requirements
- Access to Kubernetes API (in-cluster or via KUBECONFIG)
- BatchSandbox mode: CRs with
sandbox.opensandbox.io/endpointsannotation containing Pod IPs - AgentSandbox mode: CRs with
status.serviceFQDNpopulated
Error Handling
The ingress provides clear HTTP status codes for different error conditions:| Error | HTTP Status | Description |
|---|---|---|
ErrSandboxNotFound | 404 | Sandbox resource does not exist |
ErrSandboxNotReady | 503 | Not enough replicas, missing endpoints, or invalid config |
| Other errors | 502 | Kubernetes API errors, etc. |
Example Error Responses
Implementation Details
Header Mode Behavior
- Routing key priority:
OpenSandbox-Ingress-Toheader first, otherwise Host parsing<sandbox-name>-<port>.* - Sandbox lookup: Sandbox name extracted from request is used to query the sandbox CR via informer cache
- Path preservation: The original request path is preserved and forwarded to the target sandbox
- Header stripping:
OpenSandbox-Ingress-Toheader is removed before proxying
URI Mode Behavior
- Path parsing: Routing information extracted from URI path:
/<sandbox-id>/<sandbox-port>/<path-to-request> - Sandbox lookup: The sandbox ID and port are extracted from the first two path segments
- Path rewriting: The remaining path is forwarded to the target sandbox as the request URI
- Default path: If no remaining path is provided, the request URI defaults to
/
WebSocket Support
- Forwards essential headers and
X-Forwarded-*headers - Supports bidirectional communication
- Proper connection upgrade handling
- Compatible with both routing modes
Development
Directory Structure
main.go: Entry point and HTTP handlerspkg/proxy/: HTTP/WebSocket proxy logic, sandbox endpoint resolutionpkg/sandbox/: Sandbox provider abstraction and BatchSandbox implementationversion/: Build metadata output (populated via ldflags)
Testing
Build Metadata
The ingress prints build metadata at startup:Support
- Issues: GitHub Issues
- Documentation: OpenSandbox Docs
- Community: Discussions