Open a TCP tunnel to a port inside the sandbox.
Creates a local TCP listener that forwards connections through a yamux-multiplexed WebSocket to the specified port inside the sandbox. Works with any TCP protocol (databases, Redis, HTTP, etc.).
Usage::
async with await sandbox.tunnel(remote_port=5432) as t:
conn = await asyncpg.connect(host="127.0.0.1", port=t.local_port)
tunnel(
self,
remote_port: int,
*,
local_port: int = 0,
max_reconnects: int = 3,
headers: RequestHeaders = None
) -> AsyncTunnel| Name | Type | Description |
|---|---|---|
remote_port* | int | TCP port inside the sandbox to tunnel to (1-65535). |
local_port | int | Default: 0Local port to listen on. Defaults to mirroring remote_port. Use 0 to let the OS pick an available port. |
max_reconnects | int | Default: 3Maximum number of automatic reconnect attempts when the WebSocket session drops. Set to 0 to disable. |