# Cloud sandboxes

> Cloud sandboxes: a module's throwaway machine at a cloud provider (boat.dev in v1), on Nexus's own provider account, for commands Nexus does not trust. Nexus Review's agent runs its commands in one. Only Nexus Review's module key may use them (`cloud.sandboxes.use`, product `robustness`, capability `review`). A sandbox gets no Nexus token and no files. At most `NEXUS_CLOUD_MAX_SANDBOXES` live at once; one more is refused, with no queue. Gateway charges a sandbox's running time to the organization as cloud compute (product `cloud`, capability `compute` in GET /v1/spend), from its create to its delete, and deletes it at its `expiresAt`. Without a provider account on the Gateway (`BOAT_API_KEY`), every route answers 503 `cloud_unavailable`.

## Create cloud sandbox

`POST /v1/cloud/sandboxes`

Create a throwaway sandbox for untrusted commands. Send `ttlSeconds` (60 to 7200): Gateway deletes the sandbox then, and the provider's own timer stops it. `size` is one of `NEXUS_CLOUD_SIZES` (`small` when absent). `labels` are at most 16, keys and values of at most 64 characters; Gateway adds `nexus.sandbox` and `nexus.tenant` itself. The sandbox starts from `NEXUS_CLOUD_SANDBOX_IMAGE` with no Nexus token and no files. Send an `Idempotency-Key`: the sandbox's id is derived from it, so a resend names the sandbox the first send made. Its running time is charged as cloud compute from the create.

Permission: `cloud.sandboxes.use` (module keys).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

### Request body (application/json, required)

- `size` ("small" | "default" | "large" | "xlarge"): One of `NEXUS_CLOUD_SIZES`; `small` when absent.
- `ttlSeconds` (integer, required) [min 60; max 7200]
- `labels` (object): Keys of 1 to 64 characters, not starting with `nexus.`.

### Responses

- `200` The sandbox a send with this key made (application/json, CloudSandbox)
  - `id` (string, required): `csb_…`
  - `state` ("creating" | "starting" | "ready" | "failed" | "gone", required)
  - `size` ("small" | "default" | "large" | "xlarge", required)
  - `labels` (object, required): The labels the create sent.
  - `createdAt` (string (date-time), required)
  - `expiresAt` (string (date-time), required): When Gateway deletes the sandbox.
  - `error` (string | null, required): Why it failed; null otherwise.
- `201` Created: the sandbox is starting (application/json, CloudSandbox)
  - `id` (string, required): `csb_…`
  - `state` ("creating" | "starting" | "ready" | "failed" | "gone", required)
  - `size` ("small" | "default" | "large" | "xlarge", required)
  - `labels` (object, required): The labels the create sent.
  - `createdAt` (string (date-time), required)
  - `expiresAt` (string (date-time), required): When Gateway deletes the sandbox.
  - `error` (string | null, required): Why it failed; null otherwise.
- `400` The body is not an object, or `size` (`invalid_size`), `ttlSeconds` (`invalid_ttl`) or `labels` (`invalid_labels`) is out of bounds.
- `402` Nothing covers 15 minutes of this sandbox's cloud compute (`budget_exceeded`), or the organization is past due (`payment_past_due`). The refusal is recorded.
- `403` Cloud machines are not turned on for this organization (`cloud_not_enabled`), or the key is not Nexus Review's module key (`role_required`, `module_key`).
- `422` This `Idempotency-Key` names another sandbox (`idempotency_key_reused`); send a new key.
- `429` Gateway runs its most sandboxes (`cloud_capacity`, `NEXUS_CLOUD_MAX_SANDBOXES`), or the provider is busy (`cloud_busy`). There is no queue: try again after `Retry-After`.
- `502` The cloud provider failed or did not answer (`cloud_provider_error`); try again.
- `503` No provider account on this Gateway (`cloud_unavailable`), or the provider has no free machine (`cloud_capacity`); try again later.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 400 |  | The body is not an object, or `size` (`invalid_size`), `ttlSeconds` (`invalid_ttl`) or `labels` (`invalid_labels`) is out of bounds. |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 402 | `budget_exceeded` | Nothing covers 15 minutes of this sandbox's cloud compute (`budget_exceeded`), or the organization is past due (`payment_past_due`). The refusal is recorded. |
| 403 | `role_required` | Your role does not have this permission |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 |  | This `Idempotency-Key` names another sandbox (`idempotency_key_reused`); send a new key. |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Gateway runs its most sandboxes (`cloud_capacity`, `NEXUS_CLOUD_MAX_SANDBOXES`), or the provider is busy (`cloud_busy`). There is no queue: try again after `Retry-After`. |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 502 |  | The cloud provider failed or did not answer (`cloud_provider_error`); try again. |
| 503 |  | No provider account on this Gateway (`cloud_unavailable`), or the provider has no free machine (`cloud_capacity`); try again later. |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/cloud/sandboxes" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "ttlSeconds": 60
  }'
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fcloud%2Fsandboxes)

## Get cloud sandbox

`GET /v1/cloud/sandboxes/{id}`

Your organization's sandbox, its state read from the provider. A deleted or expired one answers `gone`.

Permission: `cloud.sandboxes.use` (module keys).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The sandbox's id (`csb_…`), as POST /v1/cloud/sandboxes answered it |

### Responses

- `200` OK (application/json, CloudSandbox)
  - `id` (string, required): `csb_…`
  - `state` ("creating" | "starting" | "ready" | "failed" | "gone", required)
  - `size` ("small" | "default" | "large" | "xlarge", required)
  - `labels` (object, required): The labels the create sent.
  - `createdAt` (string (date-time), required)
  - `expiresAt` (string (date-time), required): When Gateway deletes the sandbox.
  - `error` (string | null, required): Why it failed; null otherwise.
- `403` The key is not Nexus Review's module key (`role_required`), or a person's or another credential's (`module_key`, `role_required`).
- `404` No such sandbox in your organization: another organization's is as absent as a missing one.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `503` No provider account on this Gateway (`cloud_unavailable`); try again later.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such sandbox in your organization: another organization's is as absent as a missing one. |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 503 |  | No provider account on this Gateway (`cloud_unavailable`); try again later. |

### Example

```sh
curl "$NEXUS_URL/v1/cloud/sandboxes/<id>" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Fcloud%2Fsandboxes%2F%7Bid%7D)

## Delete cloud sandbox

`DELETE /v1/cloud/sandboxes/{id}`

Delete the sandbox at the provider and charge its running time. A sandbox already gone answers the same.

Permission: `cloud.sandboxes.use` (module keys).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The sandbox's id (`csb_…`), as POST /v1/cloud/sandboxes answered it |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

### Responses

- `200` OK (application/json, CloudSandboxDeleted)
  - `id` (string, required)
  - `deleted` (boolean, required)
- `403` The key is not Nexus Review's module key (`role_required`), or a person's or another credential's (`module_key`, `role_required`).
- `404` No such sandbox in your organization: another organization's is as absent as a missing one.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `502` The cloud provider failed or did not answer (`cloud_provider_error`); try again.
- `503` No provider account on this Gateway (`cloud_unavailable`); try again later.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such sandbox in your organization: another organization's is as absent as a missing one. |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 502 |  | The cloud provider failed or did not answer (`cloud_provider_error`); try again. |
| 503 |  | No provider account on this Gateway (`cloud_unavailable`); try again later. |

### Example

```sh
curl -X DELETE "$NEXUS_URL/v1/cloud/sandboxes/<id>" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#delete%3A%2Fv1%2Fcloud%2Fsandboxes%2F%7Bid%7D)

## Exec cloud sandbox

`POST /v1/cloud/sandboxes/{id}/exec`

Run one command in the sandbox with `sh -c` and wait for it. `command` is 1 to 16384 bytes and `timeoutSeconds` 1 to 600: the provider stops the command then and answers `timedOut`. `stdoutTruncated` and `stderrTruncated` say the provider cut that stream. The call waits up to `timeoutSeconds` plus 30 seconds.

Permission: `cloud.sandboxes.use` (module keys).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The sandbox's id (`csb_…`), as POST /v1/cloud/sandboxes answered it |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

### Request body (application/json, required)

- `command` (string, required): Run with `sh -c`; at most 16384 bytes. [min length 1]
- `timeoutSeconds` (integer, required) [min 1; max 600]

### Responses

- `200` OK (application/json, CloudSandboxExecResult)
  - `exitCode` (integer | null, required): Null when the command was killed (a timeout or a signal).
  - `stdout` (string, required)
  - `stderr` (string, required)
  - `timedOut` (boolean, required)
  - `durationMs` (integer, required) [min 0]
  - `stdoutTruncated` (boolean, required): The provider cut stdout: its text is not complete.
  - `stderrTruncated` (boolean, required): The provider cut stderr: its text is not complete.
- `400` `command` (`invalid_command`) or `timeoutSeconds` (`invalid_timeout`) is out of bounds.
- `403` The key is not Nexus Review's module key (`role_required`), or a person's or another credential's (`module_key`, `role_required`).
- `404` No such sandbox in your organization: another organization's is as absent as a missing one.
- `409` The sandbox is not ready yet, or has ended (`sandbox_not_ready`); read it and try again once it is `ready`.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `502` The cloud provider failed or did not answer (`cloud_provider_error`). The command may still have run: an answer larger than 1 MiB, or one lost on the way, comes after it ran. Do not send it again unless it is safe to run twice.
- `503` No provider account on this Gateway (`cloud_unavailable`); try again later.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 400 |  | `command` (`invalid_command`) or `timeoutSeconds` (`invalid_timeout`) is out of bounds. |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such sandbox in your organization: another organization's is as absent as a missing one. |
| 409 |  | The sandbox is not ready yet, or has ended (`sandbox_not_ready`); read it and try again once it is `ready`. |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 502 |  | The cloud provider failed or did not answer (`cloud_provider_error`). The command may still have run: an answer larger than 1 MiB, or one lost on the way, comes after it ran. Do not send it again unless it is safe to run twice. |
| 503 |  | No provider account on this Gateway (`cloud_unavailable`); try again later. |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/cloud/sandboxes/<id>/exec" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "command": "<command>",
    "timeoutSeconds": 1
  }'
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fcloud%2Fsandboxes%2F%7Bid%7D%2Fexec)

## Cloud sandbox upload url

`POST /v1/cloud/sandboxes/{id}/upload-url`

A provider link that takes one file for the sandbox. PUT the bytes to `url` with no auth header; the provider writes them at `$HOME/<path>` (`/home/user`). `path` is relative, with no `..`, at most 256 characters. The link works for `ttlSeconds` (60 to 900, 900 when absent).

Permission: `cloud.sandboxes.use` (module keys).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The sandbox's id (`csb_…`), as POST /v1/cloud/sandboxes answered it |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

### Request body (application/json, required)

- `path` (string, required): Relative to the sandbox's home, with no `..`. [min length 1; max length 256]
- `ttlSeconds` (integer): 900 when absent. [min 60; max 900]

### Responses

- `200` OK (application/json, CloudSandboxUploadUrl)
  - `url` (string (uri), required)
- `400` `path` (`invalid_path`) or `ttlSeconds` (`invalid_ttl`) is out of bounds.
- `403` The key is not Nexus Review's module key (`role_required`), or a person's or another credential's (`module_key`, `role_required`).
- `404` No such sandbox in your organization: another organization's is as absent as a missing one.
- `409` The sandbox is not ready yet, or has ended (`sandbox_not_ready`).
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `502` The cloud provider failed or did not answer (`cloud_provider_error`); try again.
- `503` No provider account on this Gateway (`cloud_unavailable`); try again later.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 400 |  | `path` (`invalid_path`) or `ttlSeconds` (`invalid_ttl`) is out of bounds. |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such sandbox in your organization: another organization's is as absent as a missing one. |
| 409 |  | The sandbox is not ready yet, or has ended (`sandbox_not_ready`). |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 502 |  | The cloud provider failed or did not answer (`cloud_provider_error`); try again. |
| 503 |  | No provider account on this Gateway (`cloud_unavailable`); try again later. |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/cloud/sandboxes/<id>/upload-url" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "path": "<path>"
  }'
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fcloud%2Fsandboxes%2F%7Bid%7D%2Fupload-url)
