Exposing Ports
Start an HTTP server inside a sandbox and reach it from the host via sb.proxy().
ports
Demonstrates sb.proxy(): start an HTTP server inside a sandbox and send requests to it from the host process via the OpenSandbox server proxy.
Setup
bunx alineo-cli init # starts OpenSandbox in Docker (one-time setup)Run
bun install
bun startWhat it does
- Creates a
node:22sandbox and writes a simple HTTP server to/server.js - Starts the server on port 3000 in the background
- Calls
sb.proxy(3000)to get a proxy URL and auth headers - Sends two requests from the host process and prints the JSON responses
Notes
With useServerProxy: true (the default), sb.proxy() returns a URL that routes through the OpenSandbox server (http://127.0.0.1:8080/sandboxes/{id}/proxy/3000). This works regardless of Docker networking because the server relays the request to the container on your behalf.