> ## 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

> Complete reference for HopX CLI terminal commands - connect to interactive terminal sessions, get terminal info, and get WebSocket URLs for terminal access.

Connect to interactive terminal sessions in HopX sandboxes using the `terminal` command (alias: `term`). Access WebSocket-based terminal sessions for interactive shell access.

## Command Syntax

```bash theme={null}
hopx terminal <subcommand> [options]
```

## Subcommands

### `connect`

Connect to an interactive terminal session.

**Syntax:**

```bash theme={null}
hopx terminal connect SANDBOX_ID [OPTIONS]
```

**Arguments:**

* `SANDBOX_ID` - Sandbox ID (required)

**Options:**

* `--command TEXT` - Command to execute (default: interactive shell)
* `--timeout INTEGER` - Connection timeout in seconds

**Examples:**

```bash theme={null}
# Connect to interactive terminal
hopx terminal connect sb_abc123

# Execute command and exit
hopx terminal connect sb_abc123 --command "ls -la"

# Connect with timeout
hopx terminal connect sb_abc123 --timeout 60
```

**Expected Output:**

```
Connected to terminal session
$ 
```

**Exit Codes:**

* `0` - Success
* `3` - Authentication error
* `4` - Sandbox not found
* `5` - Connection timeout

### `info`

Get terminal information for a sandbox.

**Syntax:**

```bash theme={null}
hopx terminal info SANDBOX_ID [OPTIONS]
```

**Arguments:**

* `SANDBOX_ID` - Sandbox ID (required)

**Options:**

* `--output, -o FORMAT` - Output format: `table`, `json`, `plain` (default: `table`)

**Examples:**

```bash theme={null}
# Get terminal info
hopx terminal info sb_abc123

# Get info with JSON output
hopx terminal info sb_abc123 --output json
```

**Expected Output (Table):**

```
┌─────────────┬─────────────────────────────────────┐
│ Property    │ Value                               │
├─────────────┼─────────────────────────────────────┤
│ Status      │ active                              │
│ WebSocket   │ wss://...                           │
│ Terminal    │ /bin/bash                           │
└─────────────┴─────────────────────────────────────┘
```

**Exit Codes:**

* `0` - Success
* `3` - Authentication error
* `4` - Sandbox not found

### `url`

Get WebSocket URL for terminal access.

**Syntax:**

```bash theme={null}
hopx terminal url SANDBOX_ID [OPTIONS]
```

**Arguments:**

* `SANDBOX_ID` - Sandbox ID (required)

**Examples:**

```bash theme={null}
# Get terminal WebSocket URL
hopx terminal url sb_abc123
```

**Expected Output:**

```
wss://terminal-sb_abc123.us-east.vms.hopx.dev/
```

**Exit Codes:**

* `0` - Success
* `3` - Authentication error
* `4` - Sandbox not found

## Interactive Terminal Usage

When connected to an interactive terminal:

* Type commands as you would in a normal terminal
* Press `Ctrl+C` to interrupt running commands
* Press `Ctrl+D` or type `exit` to disconnect
* Use arrow keys for command history
* Tab completion is available

## Shell Scripting Examples

### Connect and Execute Commands

```bash theme={null}
#!/bin/bash

# Connect and run commands
echo "ls -la" | hopx terminal connect sb_abc123 --command "bash"
```

### Get Terminal URL for External Tools

```bash theme={null}
#!/bin/bash

# Get terminal URL for use with external WebSocket clients
TERMINAL_URL=$(hopx terminal url sb_abc123)
echo "Terminal URL: $TERMINAL_URL"
```

## Related

* **[CLI Quickstart](/cli/quickstart)** - Get started with CLI
* **[Sandbox Commands](/cli/commands/sandbox)** - Create and manage sandboxes
* **[Shell Commands](/cli/commands/cmd)** - Run non-interactive shell commands
* **[Python SDK: Terminal](/sdk/python/terminal)** - Python SDK terminal access
* **[JavaScript SDK: Terminal](/sdk/javascript/terminal)** - JavaScript SDK terminal access
* **[API: Terminal](/api/vm-agent/terminal)** - REST API endpoints

## Next Steps

* Learn about [Sandbox Management](/cli/commands/sandbox) to create sandboxes
* Explore [Shell Commands](/cli/commands/cmd) for non-interactive command execution
* Review [Code Execution](/cli/commands/run) to run code in sandboxes
