> ## Documentation Index
> Fetch the complete documentation index at: https://opensandbox-oc-s-762ac928075c46d2828bcb22.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Interactive Terminals

> Full PTY sessions inside sandboxes

A PTY session is a full interactive terminal inside the sandbox — like SSH but over WebSocket. Supports colors, cursor movement, and full-screen applications (vim, htop).

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { Sandbox } from "@opencomputer/sdk";

  const sandbox = await Sandbox.create();
  const pty = await sandbox.pty.create({
    onOutput: (data) => process.stdout.write(data),
  });

  pty.send("ls -la /app\n");
  // ... wait for output ...
  pty.close();
  await sandbox.kill();
  ```

  ```python Python theme={null}
  from opencomputer import Sandbox

  sandbox = await Sandbox.create()
  pty = await sandbox.pty.create(
      on_output=lambda data: print(data.decode(), end=""),
  )

  pty.send("ls -la /app\n")
  output = await pty.recv()  # pull-based alternative
  pty.close()
  await sandbox.kill()
  ```
</CodeGroup>

## Creating a PTY

<CodeGroup>
  ```typescript TypeScript theme={null}
  const pty = await sandbox.pty.create({
    cols: 120,
    rows: 40,
    onOutput: (data) => process.stdout.write(data),
  });
  ```

  ```python Python theme={null}
  pty = await sandbox.pty.create(
      cols=120,
      rows=40,
      on_output=lambda data: print(data.decode(), end=""),
  )
  ```
</CodeGroup>

### Parameters

| Parameter  | Type     | Default | Description                                                 |
| ---------- | -------- | ------- | ----------------------------------------------------------- |
| `cols`     | number   | `80`    | Terminal columns                                            |
| `rows`     | number   | `24`    | Terminal rows                                               |
| `onOutput` | callback | —       | Called with output data (TS: `Uint8Array`, Python: `bytes`) |

## PtySession

| Member         | TypeScript              | Python              | Description                 |
| -------------- | ----------------------- | ------------------- | --------------------------- |
| Session ID     | `pty.sessionId`         | `pty.session_id`    | Unique session ID           |
| Send input     | `pty.send(data)`        | `pty.send(data)`    | Send keystrokes or commands |
| Receive output | via `onOutput` callback | `await pty.recv()`  | Get terminal output         |
| Close          | `pty.close()`           | `await pty.close()` | Close the PTY session       |

<Note>
  `recv()` is Python-only — a pull-based alternative to the `on_output` callback. Returns raw bytes.
</Note>

### Resize

PTY resize is available via the [HTTP API](/reference/api#pty) only (`POST /api/sandboxes/:id/pty/:sessionID/resize`). The SDKs do not expose a resize method — the CLI handles resize automatically for interactive sessions.

## CLI

The fastest way to get an interactive shell:

```bash theme={null}
oc shell sb-abc123
oc shell sb-abc123 --shell /bin/zsh
```

Terminal size is auto-detected and resize events are forwarded. See [`oc shell`](/cli/shell) for details.

<Tip>
  CLI equivalent: [`oc shell`](/cli/shell). Full reference: [TypeScript SDK](/reference/typescript-sdk#pty) · [Python SDK](/reference/python-sdk#pty) · [HTTP API](/reference/api#pty).
</Tip>
