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_tunnelTunnel
Class●Since v0.7

Tunnel

TCP tunnel to a port inside a sandbox.

Opens a local TCP listener and forwards each accepted connection through a yamux-multiplexed WebSocket to the daemon, which dials the target port inside the sandbox.

Typically used as a context manager::

with sandbox.tunnel(remote_port=5432) as t:
    conn = psycopg2.connect(host="127.0.0.1", port=t.local_port)

Or with explicit lifecycle::

t = sandbox.tunnel(remote_port=5432)
# ... use tunnel ...
t.close()
Copy
Tunnel(
  self,
  dataplane_url: str,
  api_key: Optional[str],
  remote_port: int,
  *,
  local_port: int = 0,
  max_reconnects: int = 3
)

Constructors

constructor
__init__
NameType
dataplane_urlstr
api_keyOptional[str]
remote_portint
local_portint
max_reconnectsint

Attributes

attribute
local_port: int

Local port the tunnel is listening on.

attribute
remote_port: int

Port inside the sandbox that the tunnel connects to.

Methods

method
close

Shut down the tunnel, closing all connections.

View source on GitHub