# Tunnel

> **Class** in `langsmith`

📖 [View in docs](https://reference.langchain.com/python/langsmith/sandbox/_tunnel/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()

## Signature

```python
Tunnel(
    self,
    dataplane_url: str,
    api_key: Optional[str],
    remote_port: int,
    *,
    local_port: int = 0,
    max_reconnects: int = 3,
    headers: Optional[Mapping[str, str]] = None,
)
```

## Constructors

```python
__init__(
    self,
    dataplane_url: str,
    api_key: Optional[str],
    remote_port: int,
    *,
    local_port: int = 0,
    max_reconnects: int = 3,
    headers: Optional[Mapping[str, str]] = None,
) -> None
```

| Name | Type |
|------|------|
| `dataplane_url` | `str` |
| `api_key` | `Optional[str]` |
| `remote_port` | `int` |
| `local_port` | `int` |
| `max_reconnects` | `int` |
| `headers` | `Optional[Mapping[str, str]]` |


## Properties

- `local_port`
- `remote_port`

## Methods

- [`close()`](https://reference.langchain.com/python/langsmith/sandbox/_tunnel/Tunnel/close)

---

[View source on GitHub](https://github.com/langchain-ai/langsmith-sdk/blob/6a74bf5af9e542d8065af8edca54b2448f430916/python/langsmith/sandbox/_tunnel.py#L171)