POST /compat/e2b/v2/sandboxes/{sandboxID}/connect
E2B's `POST /v2/sandboxes/{sandboxID}/connect`. Returns the running sandbox (`200`), or resumes a paused one first (`201`, which needs `sandboxes:write` as the native resume does), with a new envd access token bound to this key: the previous token stays valid 60 seconds more, so handles opened before the connect keep working through the switch. `timeout` (seconds), when given, sets the sandbox's new end as the timeout operation does. Needs `sandboxes:run`. `memory: false` (a reboot instead of a restore) is refused with `400`.

Authentication

Bearer Token (b3os_sk_ API key or b3os_pat_ token)

Path Parameters

sandboxID string required path
The sandbox, as `sbx-<ulid>` (the `sandboxID` of the create answer) or `sbx_<ulid>`.

Request Body

application/json
timeout integer
memory boolean
`false` is refused.

Responses

200 The sandbox was running; a new envd access token.
application/json
sandboxID string REQUIRED
templateID string REQUIRED
clientID string REQUIRED
envdVersion string REQUIRED
The envd protocol version the SDKs check features against.
envdAccessToken string REQUIRED
The envd access token (`b3os_et_…`): valid at most 1 hour, while the sandbox is running or paused and the key that minted it is not revoked. Returned only here and by connect.
domain string | null
201 The sandbox was paused and is running again; a new envd access token.
400 A malformed value, or an option B3OS cannot honor named in the message (`invalid_request`, `unsupported_option`).
401 Missing or invalid B3OS key in `X-API-KEY` (`unauthorized`).
403 The key lacks a scope the operation needs (`forbidden`).
404 No such live sandbox, template or file (`sandbox_not_found`, `template_not_found`, `file_not_found`).
curl -X POST 'https://beta-api.b3os.org/compat/e2b/v2/sandboxes/string/connect' \  -H 'Authorization: Bearer YOUR_API_TOKEN' \  -H 'Content-Type: application/json' \  -d '{  "timeout": 300}'
const response = await fetch('https://beta-api.b3os.org/compat/e2b/v2/sandboxes/string/connect', {  method: 'POST',  headers: {      "Authorization": "Bearer YOUR_API_TOKEN",      "Content-Type": "application/json"  },  body: JSON.stringify({    "timeout": 300  })});const data = await response.json();console.log(data);
import requestsheaders = {    'Authorization': 'Bearer YOUR_API_TOKEN'}response = requests.post('https://beta-api.b3os.org/compat/e2b/v2/sandboxes/string/connect', headers=headers, json={  "timeout": 300})print(response.json())
200 Response
{  "sandboxID": "sbx-01m5t68q1b590rj801nbzsqzkk",  "templateID": "base",  "clientID": "b3os",  "envdVersion": "0.5.7",  "envdAccessToken": "b3os_et_Q2tW1mWlqyB8mJ6ZdZ8Tn0b4JwTT0o4WJmTt2r5f4Hk",  "domain": null}
Ask a question... ⌘I