Architecture
OpenSandbox networking consists of two main components:Ingress Gateway
Routes external traffic to sandbox services via HTTP/HTTPS endpoints
Egress Control
Enforces network policies to restrict outbound traffic from sandboxes
Ingress routing
The Ingress Gateway provides HTTP/HTTPS access to services running inside sandboxes.How it works
- Service binding: When you create a sandbox, you can expose ports
- Dynamic routing: The gateway creates routes based on sandbox ID and port
- Endpoint generation: Get public URLs via
sandbox.get_endpoint(port) - Traffic forwarding: Requests are proxied to the sandbox container
Getting endpoints
Retrieve the public URL for a service running in a sandbox:- Python
- JavaScript
- Kotlin
Routing modes
The Ingress Gateway supports multiple routing strategies:- URI-based routing
- Header-based routing
- Wildcard subdomain
Routes based on URL path:Format: Example:
https://domain/sandboxes/{sandboxId}/port/{port}Configuration:https://api.opensandbox.io/sandboxes/sb-123/port/8000WebSocket support
The Ingress Gateway supports WebSocket connections for real-time applications:- VNC access for desktop environments
- Real-time collaboration tools
- Live terminal sessions
- Interactive debugging
Egress control
The Egress Control component restricts outbound network access from sandboxes using FQDN-based policies.Network policies
Define allowed or denied domains when creating a sandbox:- Deny by default
- Allow by default
Policy rules
Domain pattern with wildcard support:
example.com- Exact match*.example.com- All subdomains*- All domains (catch-all)
Action to take:
allow or denyRule priority (lower = higher priority). Defaults to order in array.
How egress control works
The egress sidecar intercepts DNS queries and network traffic:Deployment modes
- Docker sidecar
- Kubernetes DaemonSet
The egress sidecar runs as a separate container sharing the network namespace:Resource impact:
- CPU: ~10m (0.01 core)
- Memory: ~50 MiB
Network isolation
Docker networking modes
- Host mode
- Bridge mode
Sandbox uses the host’s network stack:Pros: Better performance, simpler port access
Cons: No network isolation, port conflictsUse case: Single-tenant environments, development
Kubernetes network policies
In Kubernetes, use NetworkPolicy for pod-level isolation:Security considerations
Recommended security configuration
Common use cases
Web application testing
Web application testing
Expose web apps for manual or automated testing:
Remote development
Remote development
Access VS Code Server or Jupyter Lab:
Restricted AI code execution
Restricted AI code execution
Allow AI-generated code to install packages but block other network access:
VNC desktop access
VNC desktop access
Access full desktop environments via VNC:
Troubleshooting
Cannot access sandbox endpoint
Cannot access sandbox endpoint
Symptoms: 502 Bad Gateway or connection refusedSolutions:
- Verify the service is running:
await sandbox.commands.run("curl localhost:8000") - Check the port number is correct
- Ensure the service binds to
0.0.0.0, not127.0.0.1 - Wait for service startup (add health check)
Egress policy not working
Egress policy not working
Symptoms: Sandbox can access blocked domainsSolutions:
- Verify egress sidecar is enabled in config
- Check sidecar container is running:
docker ps - Review policy rule order (first match wins)
- Drop NET_RAW capability to prevent raw socket access
WebSocket connections fail
WebSocket connections fail
Symptoms: WebSocket upgrade failsSolutions:
- Ensure ingress gateway supports WebSocket (OpenSandbox does)
- Check for proxies that don’t support WebSocket
- Verify the application listens on the correct port
Ingress component
Deep dive into ingress gateway architecture
Egress component
Learn about egress control implementation
Security
Security best practices for networking
Configuration
Configure networking options