---
title: TCP
url: /sdks/go/dev/api/tcp/
docset: sdk-go
version: dev
latest_version: 0.1.8
source: ai-openshell/sdk-go@main:docs/src/api/tcp.md
---

> Documentation index: /sdks/go/dev/llms.txt. This page is for Go SDK dev.
> These docs are for the development version (ai-openshell/sdk-go@main). Latest released version (0.1.8): /sdks/go/0.1.8/api/tcp.md

# TCP

Accessor: `client.TCP()`

Forward TCP connections to sandbox ports using bidirectional gRPC streaming.

## Forward

Open a bidirectional TCP forwarding stream to a specific port inside a sandbox.
Returns an `io.ReadWriteCloser` that proxies data between the caller and the
sandbox port over gRPC streaming.

```go
conn, err := client.TCP().Forward(ctx, "default", "sandbox-123", 8080)
if err != nil {
    log.Fatal(err)
}
defer conn.Close()

// Exchange protocol bytes with the service through the tunnel.
_, err = conn.Write([]byte("ping\n"))
if err != nil {
    log.Fatal(err)
}

buf := make([]byte, 4096)
n, err := conn.Read(buf)
if err != nil {
    log.Fatal(err)
}
fmt.Printf("Response: %s\n", buf[:n])
```

## Listen

Bind a local address that forwards every connection to a sandbox port. The
returned `ForwardListener` owns its accept loop and all bridge goroutines; it is
a lifecycle handle with `Addr` and `Close`, not a `net.Listener`.

```go
forward, err := client.TCP().Listen(ctx, "default", "sandbox-123", 8080, 0)
if err != nil {
    log.Fatal(err)
}
defer forward.Close()

conn, err := net.Dial("tcp", forward.Addr().String())
if err != nil {
    log.Fatal(err)
}
defer conn.Close()
```

Do not pass `ForwardListener` to `http.Serve`. Dial its address with the client
for the protocol exposed by the sandbox service.

TCP forwarding is lower-level than [SSH tunneling](/sdks/go/dev/api/ssh/). Use TCP forwarding
when you need direct port access without SSH session overhead.

See also: [SSH Tunneling](/sdks/go/dev/api/ssh/), [Error Handling](/sdks/go/dev/error-handling/)
