> ## Documentation Index
> Fetch the complete documentation index at: https://docs.e2b.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Forward a port

You can forward a port on your machine to a port inside a running sandbox with the `e2b sandbox port-forward` (alias `pf`) command.

```bash Terminal theme={"theme":"css-variables"}
e2b sandbox port-forward <sandbox-id> <local>:<remote>
```

For example, to reach a server listening on port `3000` in the sandbox at `localhost:8000`:

```bash theme={"theme":"css-variables"}
e2b sandbox port-forward <sandbox-id> 8000:3000
curl http://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](https://docs.e2b.dev/network/restrict-public-access.md).

### How it works

The sandbox downloads a [websocat](https://github.com/vi/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](https://docs.e2b.dev/network/public-url.md).

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.
