Skip to main content
You can forward a port on your machine to a port inside a running sandbox with the e2b sandbox port-forward (alias pf) command.
For example, to reach a server listening on port 3000 in the sandbox at localhost:8000:
Pass a single port to use the same number on both sides, e.g. e2b sandbox port-forward <sandbox-id> 5432. The command keeps running and forwards every TCP connection to 127.0.0.1:<local> until you stop it with Ctrl+C. It works with any TCP protocol, such as HTTP, databases, or SSH, and with sandboxes that restrict public access.

How it works

The sandbox downloads a websocat binary from GitHub (so it needs internet access) and runs it as a WebSocket server in front of the remote port. Each local connection is tunneled over its own WebSocket through the sandbox’s public URL. The tunnel runs over wss://, so traffic is encrypted between your machine and the sandbox proxy. websocat only accepts WebSocket connections on a random secret path that the command generates each time it starts websocat, so the relay can’t be reached by someone who only knows the sandbox ID, even when the sandbox allows public traffic. The command stops websocat when it exits. A second port-forward to the same remote port shares the first one’s websocat and stops when the first one does.