# Terminal

An interactive shell in a running sandbox, for looking around when something goes wrong – from the portal, from your computer or over a WebSocket.

## In the portal

Open *Sandboxes*, pick a running sandbox and click *Terminal*. See [Using the portal](https://sandbox.wbx.cz/docs/portal.md).

## From your computer – `wbx connect`

The Python SDK installs the `wbx` command:

```
pip install wbxsandbox
export WBXSANDBOX_URL=https://sandbox.wbx.cz WBXSANDBOX_API_KEY=YOUR_API_KEY
wbx connect SB_ID
```

It reads `WBXSANDBOX_URL` and `WBXSANDBOX_API_KEY`, or `--url` and `--key`. Type `exit` to end the shell, or press `Ctrl`+`]` to disconnect. Works in Linux and macOS terminals; Windows support (Windows 10 or newer) is experimental. Behind a company proxy it uses `HTTPS_PROXY` / `NO_PROXY` like other command-line tools.

- The terminal runs over a WebSocket on the same address as the API (port 443), so nothing else needs to be open.
- Closing it ends the shell; the sandbox keeps running until its timeout and is billed as usual.
- An idle terminal (no input or output) closes after 30 minutes, and an account can have up to 10 terminals open at once.

## WebSocket API

| Endpoint | What it does |
| --- | --- |
| GET /v1/sandboxes/{id}/terminal?cols=&rows= | WebSocket (API key in the `X-API-Key` header). All messages are JSON text. Send `{"type":"input","data":"ls\r"}` (or `"data_b64"` for raw bytes) and `{"type":"resize","cols":120,"rows":40}`. You receive `{"type":"ready"}`, `{"type":"output","data":"…"}` and finally `{"type":"exit","exit_code":0}` or `{"type":"error","message":"…"}`. |

For a terminal inside your own app you can also start a process with `"pty"` – see [Background processes](https://sandbox.wbx.cz/docs/sandboxes/commands.md#processes).

Source: https://sandbox.wbx.cz/docs/sandboxes/terminal
