LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • Client
  • AsyncClient
  • Run Helpers
  • Run Trees
  • Evaluation
  • Schemas
  • Utilities
  • Wrappers
  • Anonymizer
  • Testing
  • Expect API
  • Middleware
  • Pytest Plugin
  • Deployment SDK
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

OverviewClientAsyncClientRun HelpersRun TreesEvaluationSchemasUtilitiesWrappersAnonymizerTestingExpect APIMiddlewarePytest PluginDeployment SDK
Language
Theme
Pythonlangsmithsandbox_async_sandboxAsyncSandboxtunnel
Method●Since v0.7

tunnel

Copy
tunnel(
  self,
  remote_port: int,
  *,
  local_port: int = 0,
  max_reconnects: int
View source on GitHub
=
3
,
headers
:
RequestHeaders
=
None
)
->
AsyncTunnel

Parameters

NameTypeDescription
remote_port*int
local_portint
Default:0
max_reconnectsint
Default:3

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)

TCP port inside the sandbox to tunnel to (1-65535).

Local port to listen on. Defaults to mirroring remote_port. Use 0 to let the OS pick an available port.

Maximum number of automatic reconnect attempts when the WebSocket session drops. Set to 0 to disable.