---
title: SSH
url: /sdks/go/dev/api/ssh/
docset: sdk-go
version: dev
latest_version: 0.1.8
source: ai-openshell/sdk-go@main:docs/src/api/ssh.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/ssh.md

# SSH

Accessor: `client.SSH()`

Create and manage SSH sessions for sandboxes. Supports direct SSH access and
TCP tunneling through SSH connections.

## CreateSession

Create a new SSH session for a sandbox. Returns connection details including
host, port, and authentication credentials.

```go
session, err := client.SSH().CreateSession(ctx, "default", "sandbox-123")
if err != nil {
    log.Fatal(err)
}
fmt.Printf("SSH via %s://%s:%d\n", session.GatewayScheme, session.GatewayHost, session.GatewayPort)
```

## RevokeSession

Revoke an active SSH session, immediately terminating any connections using it.

```go
deletion, err := client.SSH().RevokeSession(ctx, "default", session.Token)
if err != nil {
    log.Fatal(err)
}
if deletion.Outcome == v1.DeletionCompleted {
    fmt.Println("Session revoked")
}
```

## Tunnel

Create an SSH tunnel that provides a bidirectional stream to a port inside a
sandbox. This combines SSH session creation with TCP forwarding into a single
operation, returning an `io.ReadWriteCloser` for the tunnel.

```go
tunnel, err := client.SSH().Tunnel(ctx, "default", "my-sandbox", 8080)
if err != nil {
    log.Fatal(err)
}
defer tunnel.Close()

// Use the tunnel as a regular io.ReadWriteCloser
_, err = tunnel.Write([]byte("GET / HTTP/1.0\r\n\r\n"))
if err != nil {
    log.Fatal(err)
}
```

See also: [TCP Forwarding](/sdks/go/dev/api/tcp/), [Error Handling](/sdks/go/dev/error-handling/)
