curl --request GET \
--url https://{sandbox_key}.{domain}/shell/connect \
--header 'X-Access-Token: <api-key>'import requests
url = "https://{sandbox_key}.{domain}/shell/connect"
headers = {"X-Access-Token": "<api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {'X-Access-Token': '<api-key>'}};
fetch('https://{sandbox_key}.{domain}/shell/connect', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{sandbox_key}.{domain}/shell/connect",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"X-Access-Token: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://{sandbox_key}.{domain}/shell/connect"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("X-Access-Token", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://{sandbox_key}.{domain}/shell/connect")
.header("X-Access-Token", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://{sandbox_key}.{domain}/shell/connect")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["X-Access-Token"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"code": "Shell.NotFound",
"message": "<string>",
"request_id": "req-3f2b6c1e-8a0d-4f6b-9c3e-2d7a1b5e9f40"
}{
"code": "Auth.Unauthorized",
"message": "unauthorized",
"request_id": "req-3f2b6c1e-8a0d-4f6b-9c3e-2d7a1b5e9f40"
}{
"code": "Shell.NotFound",
"message": "<string>",
"request_id": "req-3f2b6c1e-8a0d-4f6b-9c3e-2d7a1b5e9f40"
}{
"code": "Shell.NotFound",
"message": "no shell session for this sandbox",
"request_id": "req-7f3c"
}{
"code": "Shell.AlreadyAttached",
"message": "shell already has an active connection",
"request_id": "req-7f3c"
}{
"code": "Shell.NotFound",
"message": "<string>",
"request_id": "req-3f2b6c1e-8a0d-4f6b-9c3e-2d7a1b5e9f40"
}{
"code": "Shell.NotFound",
"message": "<string>",
"request_id": "req-3f2b6c1e-8a0d-4f6b-9c3e-2d7a1b5e9f40"
}Attach to the sandbox shell (WebSocket)
WebSocket handshake — not a normal GET. Code generators produce no
usable client for this operation (see x-websocket); consumers use a
WebSocket library instead. The address is composed from the POST /shell
response: wss://{sandbox_key}.{domain}{connect_url} — the same
data-plane host, scheme wss.
The client sends the standard upgrade headers (Upgrade: websocket,
Connection: Upgrade, plus the Sec-WebSocket-* headers WebSocket
libraries add automatically) together with the same X-Access-Token
used by the other data-plane endpoints. When a browser sends an Origin
header, it must be on the server allowlist, otherwise the handshake is
refused with 403.
After the 101 upgrade the connection switches to WebSocket framing:
- BINARY frames only. client→server frames carry raw terminal input bytes; server→client frames carry raw terminal output bytes (ANSI escape sequences included, xterm.js-compatible).
- Text frames are a protocol violation: the server drops the connection.
- No JSON messages in-band. Resize and close go through
POST /shell/control, never over the WebSocket. - At most one active connection per sandbox; a second concurrent
attach is refused at handshake time with
409. - Disconnecting keeps the shell alive — reattaching resumes the same
session. Only
POST /shell/controlwithaction=closedestroys it.
Pre-upgrade errors are returned as plain HTTP responses (see below).
curl --request GET \
--url https://{sandbox_key}.{domain}/shell/connect \
--header 'X-Access-Token: <api-key>'import requests
url = "https://{sandbox_key}.{domain}/shell/connect"
headers = {"X-Access-Token": "<api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {'X-Access-Token': '<api-key>'}};
fetch('https://{sandbox_key}.{domain}/shell/connect', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{sandbox_key}.{domain}/shell/connect",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"X-Access-Token: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://{sandbox_key}.{domain}/shell/connect"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("X-Access-Token", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://{sandbox_key}.{domain}/shell/connect")
.header("X-Access-Token", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://{sandbox_key}.{domain}/shell/connect")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["X-Access-Token"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"code": "Shell.NotFound",
"message": "<string>",
"request_id": "req-3f2b6c1e-8a0d-4f6b-9c3e-2d7a1b5e9f40"
}{
"code": "Auth.Unauthorized",
"message": "unauthorized",
"request_id": "req-3f2b6c1e-8a0d-4f6b-9c3e-2d7a1b5e9f40"
}{
"code": "Shell.NotFound",
"message": "<string>",
"request_id": "req-3f2b6c1e-8a0d-4f6b-9c3e-2d7a1b5e9f40"
}{
"code": "Shell.NotFound",
"message": "no shell session for this sandbox",
"request_id": "req-7f3c"
}{
"code": "Shell.AlreadyAttached",
"message": "shell already has an active connection",
"request_id": "req-7f3c"
}{
"code": "Shell.NotFound",
"message": "<string>",
"request_id": "req-3f2b6c1e-8a0d-4f6b-9c3e-2d7a1b5e9f40"
}{
"code": "Shell.NotFound",
"message": "<string>",
"request_id": "req-3f2b6c1e-8a0d-4f6b-9c3e-2d7a1b5e9f40"
}Authorizations
Sandbox data-plane token — the sandbox_access_token returned by the create/connect endpoints. Used for /files, Sandbox-Exec, and other data-plane endpoints; the control plane (/api/v2) does not accept it, and conversely the control plane's Authorization: Bearer is invalid on the data plane.
The token is bound to its sandbox: using sandbox A's token against sandbox B's host fails. It stays valid until the sandbox's lifetime ends; there is no separate rotation endpoint (rotate_traffic_token rotates the port traffic token traffic_access_token and does not affect this one).
Response
Handshake succeeded. The connection is now a WebSocket carrying raw
terminal bytes in BINARY frames; see the operation description for
the framing protocol. If attaching to the shell fails after the upgrade,
the server closes the WebSocket with close code 1011 and reason
attach failed.