Prerequisites
- An API key from the console, exported as
BOXLITE_API_KEY. See API keys. pip install boxlite, and the REST URL exported asBOXLITE_REST_URL. See Quickstart.
How a tunnel reaches your service
You do not open a port on the platform. You ask one specific box for a tunnel to one specific port inside it, andawait box.network.tunnel(port) prepares it.
Behind that single call: the SDK asks the Cloud API to prepare the tunnel (POST /v1/boxes/{id}/network/tunnel if you are driving the REST API yourself), opens a TLS connection to the public proxy, and issues an HTTP CONNECT. The proxy connects on to the runner hosting your box, and the runner connects to the guest port. From there the path is your service’s socket: the tunnel moves bytes and nothing along it interprets your protocol.
Two consequences shape every use of a tunnel.
- Your service must bind
0.0.0.0. The tunnel terminates on the box’s network interface, so a server bound to127.0.0.1inside the box is unreachable — the same reason port forwarding needs0.0.0.0on a box you run yourself, explained in Network access. - A prepared tunnel carries exactly one connection. See A tunnel is one-shot.
A tunnel is one-shot
Preparing a tunnel is cheap and boxes accept several at once, so this is a shape to lean into rather than work around: many concurrent clients on the same guest port each get their own tunnel, and different guest ports on one box can be tunnelled at the same time.Parameters and returns
box.network.tunnel(port)
Async. Prepares one tunnel to one port inside one box.
Returns a
BoxTunnel. await box.tunnel(port) is an equivalent shorthand on a SimpleBox.
BoxTunnel
SocketAddress
Two class methods build the address forward() listens on.
Read-only attributes:
TunnelForwarder
BoxConnection
What a tunnel carries
These behaviors are verified end to end against BoxLite Cloud, so you can build on them:- HTTP requests and responses,
GETandPOST. - WebSocket — the upgrade handshake and frames in both directions.
- Several guest ports on one box, tunnelled at the same time.
- Concurrent clients against the same guest port, each on its own tunnel.
- Responses larger than 2 MiB through a single connection, byte-for-byte intact.
- Slow readers — a client that drains the stream slowly does not lose data.
- Client cancellation — abandoning your side ends that stream without disturbing the box or its other streams.
- Service restart — restart the server inside the box, open a fresh tunnel, and traffic flows again.
- Arbitrary TCP, including a real SSH session to an
sshdlistening on port 2222. The path is not HTTP-specific.
Limits
Three properties of this path to design around. ACONNECT to a stopped box can be accepted before the stream fails. A successful connect is not proof that the box is running — the accept can land and the stream fail immediately afterwards. Treat your first successful read or write as the readiness signal. Tunnel traffic also does not wake a stopped box: the console is explicit that preview traffic keeps a running box alive but does not wake a stopped one, so start the box yourself and check Stop when idle if it stops under you.
A response can be lost after shutdown_write(). TCP half-close is not carried end to end, so a guest that waits for end-of-input before it replies may never reply, and a reply already in flight can be dropped. Use a protocol that frames its own messages — a newline, a length prefix, Content-Length — instead of one that signals “done” with EOF.
Direct browser use of a tunnel URL is not covered. The URL from uri() is the address the SDK dials when you call connect() or forward(). Navigating to it in a browser, and browser authentication for a private box, sit outside the verified path. Drive tunnels from the SDK, and when you want a browser on the service, forward the port to your machine with Port forwarding.
Troubleshooting
Next steps
Serve HTTP
Start a server inside a box and reach it over a tunnel.
Port forwarding
Publish a box port on your own machine.
Raw streams
Read and write bytes for a protocol of your own.
Network policy
Who can reach the box, and what the box can reach.

