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

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)
Copy
tunnel(
  self,
  remote_port: int,
  *,
  local_port: int = 0,
  max_reconnects: int = 3,
  headers: RequestHeaders = None
) -> AsyncTunnel

Parameters

NameTypeDescription
remote_port*int

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

local_portint
Default:0

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

max_reconnectsint
Default:3

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

View source on GitHub