#Port Exposure
Expose sandbox ports to make services accessible via public URLs. This allows external access to web servers, APIs, and other services running inside a sandbox.
Exposed Port Model#
| Field | Type | Description |
|---|---|---|
port | integer | Port number exposed inside the sandbox |
resume | boolean | Auto-resume sandbox when traffic hits this port |
public_url | string | Public URL for accessing the exposed port (read-only) |
When resume is enabled, a paused sandbox will automatically resume when receiving traffic on the exposed port.
Get Exposed Ports#
List all exposed ports for a sandbox.
/api/v1/sandboxes/{id}/exposed-ports
Response#
| Field | Type | Description |
|---|---|---|
sandbox_id | string | Sandbox ID |
exposed_ports | array | List of exposed port configurations |
exposure_domain | string | Base domain for public URLs (e.g., aws-us-east-1.sandbox0.app) |
go// Claim a sandbox from the "default" template sandbox, err := client.ClaimSandbox(ctx, "default", sandbox0.WithSandboxHardTTL(300), sandbox0.WithSandboxEnvVars(map[string]string{ "APP_ENV": "development", }), sandbox0.WithSandboxAutoResume(true), ) if err != nil { log.Fatal(err) } fmt.Printf("Sandbox ID: %s\n", sandbox.ID) defer client.DeleteSandbox(ctx, sandbox.ID) // Get all exposed ports ports, err := sandbox.GetExposedPorts(ctx) if err != nil { log.Fatal(err) } fmt.Printf("Exposure domain: %s\n", ports.ExposureDomain) for _, p := range ports.Ports { fmt.Printf("Port %d: %s\n", p.Port, p.PublicURL) }
Expose a Port#
Expose a port to make it publicly accessible.
/api/v1/sandboxes/{id}/exposed-ports
Request Body#
| Field | Type | Description |
|---|---|---|
ports | array | List of port configurations to expose |
go// Expose port 8080 with auto-resume resp, err := sandbox.ExposePort(ctx, 8080, true) if err != nil { log.Fatal(err) } fmt.Printf("Exposure domain: %s\n", resp.ExposureDomain) for _, p := range resp.Ports { fmt.Printf("Port %d -> %s\n", p.Port, p.PublicURL) }
Expose Multiple Ports#
Expose multiple ports at once.
go// Expose multiple ports resp, err = sandbox.UpdateExposedPorts(ctx, []sandbox0.ExposedPort{ {Port: 8080, Resume: true}, {Port: 3000, Resume: false}, {Port: 9000, Resume: true}, }) if err != nil { log.Fatal(err) } for _, p := range resp.Ports { fmt.Printf("Port %d -> %s (resume: %v)\n", p.Port, p.PublicURL, p.Resume) }
Remove Exposed Port#
Remove a specific exposed port.
/api/v1/sandboxes/{id}/exposed-ports/{port}
go// Remove exposed port 8080 _, err = sandbox.UnexposePort(ctx, 8080) if err != nil { log.Fatal(err) } fmt.Println("Port 8080 no longer exposed")
Clear All Exposed Ports#
Remove all exposed ports from a sandbox.
/api/v1/sandboxes/{id}/exposed-ports
go// Clear all exposed ports err = sandbox.ClearExposedPorts(ctx) if err != nil { log.Fatal(err) } fmt.Println("All ports unexposed")
Auto-Resume Feature#
When a sandbox is paused with resume: true on an exposed port, incoming traffic will automatically resume the sandbox.
go// Expose port with auto-resume _, err = sandbox.ExposePort(ctx, 8080, true) if err != nil { log.Fatal(err) } // Pause the sandbox _, err = client.PauseSandbox(ctx, sandbox.ID) if err != nil { log.Fatal(err) } // Incoming HTTP request to the public URL will automatically // resume the sandbox before routing the request
Auto-resume adds a small delay to the first request after pausing while the sandbox resumes. Subsequent requests are served immediately.
Next Steps#
Webhooks
Receive event notifications
Network Policy
Control network access
Volumes
Persistent storage for sandboxes