Skip to main content

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.ok endpoint
  • Flexible routing modes: Header-based or URI path-based routing

Architecture

Component Discovery

The ingress watches sandbox CRs in a target namespace:
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 the OpenSandbox-Ingress-To header or the Host header. Format:
  • Header: OpenSandbox-Ingress-To: <sandbox-id>-<port>
  • Host: <sandbox-id>-<port>.<domain>
Example:
Parsing Logic:
  • 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:
Parsing Logic:
  • 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 /
Use Cases:
  • When you cannot modify HTTP headers
  • When you need path-based routing
  • For simpler client configuration without custom headers

Quick Start

Endpoints:
  • / - Proxy endpoint
  • /status.ok - Health check

Configuration

Command-line Flags

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/endpoints annotation containing Pod IPs
  • AgentSandbox mode: CRs with status.serviceFQDN populated

Error Handling

The ingress provides clear HTTP status codes for different error conditions:

Example Error Responses

Implementation Details

Header Mode Behavior

  1. Routing key priority: OpenSandbox-Ingress-To header first, otherwise Host parsing <sandbox-name>-<port>.*
  2. Sandbox lookup: Sandbox name extracted from request is used to query the sandbox CR via informer cache
  3. Path preservation: The original request path is preserved and forwarded to the target sandbox
  4. Header stripping: OpenSandbox-Ingress-To header is removed before proxying

URI Mode Behavior

  1. Path parsing: Routing information extracted from URI path: /<sandbox-id>/<sandbox-port>/<path-to-request>
  2. Sandbox lookup: The sandbox ID and port are extracted from the first two path segments
  3. Path rewriting: The remaining path is forwarded to the target sandbox as the request URI
  4. 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 handlers
  • pkg/proxy/: HTTP/WebSocket proxy logic, sandbox endpoint resolution
  • pkg/sandbox/: Sandbox provider abstraction and BatchSandbox implementation
  • version/: Build metadata output (populated via ldflags)

Testing

Build Metadata

The ingress prints build metadata at startup:

Support