> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hopx.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Terminal Access

> Interactive terminal resource for WebSocket-based sandbox terminal access in HopX using the JavaScript/TypeScript SDK. Complete reference for the Terminal class including async methods for connecting to interactive terminals, executing commands in real-time, and streaming terminal output. Includes TypeScript examples for terminal automation.

**Version:** 0.1.22\
**Last Verified:** 2025-01-27\
**Package:** `@hopx-ai/sdk` on [npm](https://www.npmjs.com/package/@hopx-ai/sdk)

## Overview

The `Terminal` resource provides interactive terminal access via WebSocket.

## Methods

### `connect`

Connect to interactive terminal.

```typescript theme={null}
async terminal.connect(): Promise<WebSocket>
```

**Returns:** `Promise<WebSocket>` - WebSocket connection

***

### `sendInput`

Send input to terminal.

```typescript theme={null}
terminal.sendInput(ws: WebSocket, data: string): void
```

***

### `resize`

Resize terminal.

```typescript theme={null}
terminal.resize(ws: WebSocket, cols: number, rows: number): void
```

***

### `output`

Async iterator for terminal output.

```typescript theme={null}
async *terminal.output(ws: WebSocket): AsyncIterableIterator<TerminalMessage>
```

**Example:**

```typescript theme={null}
const ws = await sandbox.terminal.connect();
sandbox.terminal.sendInput(ws, "echo 'Hello'\n");

for await (const message of sandbox.terminal.output(ws)) {
    if (message.type === 'stdout') {
        console.log(message.data);
    }
}
```

***

## Related Classes

* **[Sandbox](/sdk/javascript/sandbox)** - Main sandbox class
* **[Types](/sdk/javascript/types)** - TypeScript type definitions

## See Also

* [Core Concepts: Terminal](/core-concepts/terminal) - Learn about terminal access
* [Sandbox Class](/sdk/javascript/sandbox) - Access terminal via `sandbox.terminal`

## Next Steps

Now that you understand terminal access, explore:

* [WebSocket Terminal](/core-concepts/terminal/websocket) - Learn terminal concepts
* [Sandbox Operations](/sdk/javascript/sandbox) - Use terminal in sandbox workflows
* [Running Commands](/core-concepts/commands/running) - Execute commands
* **[CLI Reference](/cli/introduction)** - Use HopX from the command line
* [Background Commands](/core-concepts/commands/background) - Non-blocking execution
