Skip to main content
Some clients cannot be taught to speak through an SDK — curl, a browser, a database driver, an existing library that only knows how to dial a socket. forward() publishes the tunnel on a local address so all of them just work.

Prerequisites

  • An API key from the console, exported as BOXLITE_API_KEY. See API keys.
  • pip install boxlite, and the REST URL exported as BOXLITE_REST_URL. See Quickstart.
  • A box you can start, and a service inside it that listens on a TCP port.
Every example reads both values from the environment, so nothing hard-codes a credential. forward() publishes the tunnel on an address on your machine, so any TCP client — curl, a browser, a database driver, an existing library that only knows how to dial a socket — can reach the service without knowing about BoxLite.
Three constraints on the listening address:
  • The host must be a numeric IP. SocketAddress.tcp(host="localhost") raises ValueError: tunnel listener host must be a numeric IP — pass "127.0.0.1".
  • port=0 is the default and asks the operating system for a free port. Read the port you actually got from forwarder.local_addr().port.
  • A Unix socket path must be absolute. SocketAddress.unix("relative.sock") raises ValueError: tunnel Unix socket path must be absolute.
await forwarder.wait() blocks until the forwarder finishes, which is what you await in a long-running process instead of exiting. await forwarder.close() shuts it down. The forwarder is built from a tunnel, and forward() spends that tunnel, so build each forwarder from its own fresh await box.network.tunnel(port).

Next steps

Network

How tunnels work, the full parameter reference, and the outbound boundary.

Network policy

Control what the box itself is allowed to reach.