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

# Remote Shell

CLI 的 `connect` 命令可将一个交互式终端——即 **Remote Shell**——连接到已在运行的 Sandbox。它通过 PTY 在 Sandbox 内打开一个真实的 shell,将你的按键输入流式传入,并把 shell 的输出实时传回,让你可以像坐在 Sandbox 终端前一样运行命令、查看状态和进行调试。

<Note>
  **注意:** Sandbox 必须已处于运行状态。`connect` 通过 ID 连接到已有的 Sandbox,不会创建新的 Sandbox。断开连接不会影响该 Sandbox 以及其他用户的会话。
</Note>

***

## 前提条件

连接前,先在环境变量中设置你的 API key:

```bash theme={null}
export PPIO_API_KEY=<your API key>
```

***

## 用法

```bash theme={null}
ppio sandbox connect <sandboxID>

# 使用简写别名（sandbox → sbx，connect → cn）
ppio sbx cn <sandboxID>
```

| 项目 | 值                 | 说明                       |
| -- | ----------------- | ------------------------ |
| 命令 | `sandbox connect` | 将终端连接到已在运行的 Sandbox      |
| 别名 | `sbx cn`          | `sandbox connect` 的简写形式  |
| 参数 | `<sandboxID>`     | 要连接的运行中 Sandbox 的 ID(必填) |

连接时,CLI 会打印该 Sandbox 在控制台中的 inspect URL 和一行确认信息,然后将你的终端交给 Sandbox 的 shell:

```text theme={null}
Terminal connecting to sandbox <sandboxID>
user@sandbox:~$ 
```

***

## 结束会话

按平常的方式退出 shell 即可——输入 `exit` 或按 **Ctrl+C**。CLI 会清理终端、关闭连接并打印:

```text theme={null}
Closing terminal connection to sandbox <sandboxID>
```

<Note>
  **注意:** 断开连接只会结束你自己的终端会话,不会停止或销毁 Sandbox,也不会断开连接到同一 Sandbox 的其他用户。
</Note>
