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

# Update a sandbox

Changes name, size, network policy, idle timeout or labels. Requires `manage`. A new idle timeout applies from the next activity.

`PATCH https://api.akua.dev/v1/sandboxes/{id}`

## Authorizations

- `Authorization: Bearer <token>` (BearerAuth): Bearer token for the authenticated caller.

## Headers

- `akua-context` (string): Optional workspace/scope context for the request. Carries a single workspace wire id (`ws_…`) today. Only needed for broad tokens - a workspace-owned token implies its workspace. Required string length: `1 - 53`. Example: `"ws_j572abc123def4"`.
- `if-match` (string, required): The `etag` of the resource version the client last read. Required on writes when the resource exposes an `etag` field. Mismatch returns 409 `ABORTED` with the current etag in the error metadata. Required string length: `1 - 256`. Example: `"42"`.

## Path Parameters

- `id` (string, required): Sandbox id (`sbx_...`). Pattern: `^sbx_[A-Za-z0-9]{1,64}$`. Example: `"sbx_j572abc123def456"`.

## Body

Required.

`application/json`: `UpdateSandboxBody`

- `name` (string): Display name. Required string length: `1 - 100`. Example: `"checkout-service"`.
- `size` (enum<string>): Compute size. `standard` is the only size today; larger sizes are added as new values. Available options: `"standard"`.
- `network_policy` (object): Outbound network access. `allow_all` means public internet only: HTTP on TCP port 80, TLS on TCP port 443 (including HTTPS), and public DNS. Private, link-local, cluster-internal and execution-cluster node addresses are blocked. Cluster DNS names and other ports or protocols are unavailable.
  - `mode` (enum<string>, required): Available options: `"allow_all"`.
- `idle_timeout_seconds` (integer, default 600): Seconds without API activity after which the sandbox suspends itself. Commands that are still running keep it awake. 300 to 86400; default 600. Required range: `300 <= x <= 86400`. Example: `600`.
- `labels` (record<string, string>)

## Response

### 200: Sandbox

`application/json`: `Sandbox`

- `id` (string, required): Sandbox id (`sbx_...`). Pattern: `^sbx_[A-Za-z0-9]{1,64}$`. Example: `"sbx_j572abc123def456"`.
- `workspace_id` (string, required): Required string length: `1 - 53`.
- `name` (string, required): Display name. Required string length: `1 - 100`. Example: `"checkout-service"`.
- `state` (enum<string>, required): `ACTIVE` sandboxes run commands and file operations. `SUSPENDED` sandboxes keep their files and cost only storage. `-ING` states are in flight; `FAILED` sandboxes can only be deleted. Available options: `"PROVISIONING"`, `"ACTIVE"`, `"SUSPENDING"`, `"SUSPENDED"`, `"RESUMING"`, `"DELETING"`, `"FAILED"`.
- `size` (enum<string>, required): Compute size. `standard` is the only size today; larger sizes are added as new values. Available options: `"standard"`.
- `source` (object | null, required): `null` for a sandbox created empty. Where the sandbox content comes from. `sandbox`: a copy of another sandbox from its latest snapshot (a fork). Repository, snapshot and template sources are added as new `type` values.
  - `type` (enum<string>, required): Available options: `"sandbox"`.
  - `sandbox_id` (string, required): Sandbox id (`sbx_...`). Pattern: `^sbx_[A-Za-z0-9]{1,64}$`. Example: `"sbx_j572abc123def456"`.
- `network_policy` (object, required): Outbound network access. `allow_all` means public internet only: HTTP on TCP port 80, TLS on TCP port 443 (including HTTPS), and public DNS. Private, link-local, cluster-internal and execution-cluster node addresses are blocked. Cluster DNS names and other ports or protocols are unavailable.
  - `mode` (enum<string>, required): Available options: `"allow_all"`.
- `idle_timeout_seconds` (integer, required, default 600): Seconds without API activity after which the sandbox suspends itself. Commands that are still running keep it awake. 300 to 86400; default 600. Required range: `300 <= x <= 86400`. Example: `600`.
- `env` (record<string, string>, required)
- `labels` (record<string, string>, required)
- `created_by` (object, required)
  - `type` (enum<string>, required): `user`: a workspace member. `opencode`: an OpenCode Server (`oc_...`). Available options: `"user"`, `"opencode"`.
  - `id` (string, required): Required string length: `1 - 100`.
- `usage` (object, required)
  - `active_seconds` (integer, required): Seconds the sandbox has spent `ACTIVE`, including the current active period. Required range: `x >= 0`.
  - `cpu_seconds` (integer | null, required): CPU seconds used. `null` until CPU accounting is available. Required range: `x >= 0`.
  - `egress_bytes` (integer | null, required): Bytes sent to the network. `null` until network accounting is available. Required range: `x >= 0`.
  - `ingress_bytes` (integer | null, required): Bytes received from the network. `null` until network accounting is available. Required range: `x >= 0`.
- `conditions` (object[], required): Maximum array length: `32 elements`. What needs attention now; empty when nothing does. Reasons:
  - `create-failed` (error): the sandbox could not be created; it is `FAILED` and can only be deleted.
  - `suspend-failed` (warning): the last suspend failed; the sandbox stays `ACTIVE`.
  - `resume-failed` (warning): the last resume failed; the sandbox stays `SUSPENDED`.
  - `reason` (string, required): Kebab-case reason; the resource documents the reasons it reports. Maximum string length: `64`. Pattern: `^[a-z0-9]+(?:-[a-z0-9]+)*$`. Example: `"agent-offline"`.
  - `severity` (enum<string>, required): `error`: the resource failed; the condition says why. `warning`: it is limited or held until the person acts or it recovers. `info`: worth knowing, nothing to do. Available options: `"error"`, `"warning"`, `"info"`.
  - `message` (string, required): Safe to show the person as is. Maximum string length: `512`.
  - `remedy` (object | null, required): What the person can do; null when nothing they do helps.
    - Any of:
      - `free-capacity`
        - `kind` (enum<string>, required): Available options: `"free-capacity"`.
        - `metric` (enum<string>, required): Available options: `"kaas/clusters"`, `"compute/machines"`, `"compute/cpu"`, `"compute/memory"`, `"compute/machines_concurrency"`, `"compute/managed_vm_trial"`, `"agents/turns_concurrency"`, `"agents/sandboxes"`, `"agents/sandboxes_running"`, `"agents/retained_filesystem_lifetime"`, `"codemode/executions"`, `"api/secrets_access"`, `"api/secrets_write"`, `"domain_routing/preview_hostnames"`, `"domain_routing/custom_domains"`, `"source_control/repositories"`.
        - `limit` (integer, required)
        - `usage` (integer, required)
        - `hint` (string, required): Maximum string length: `256`.
      - `upgrade-plan`
        - `kind` (enum<string>, required): Available options: `"upgrade-plan"`.
        - `metric` (enum<string>, required): Available options: `"kaas/clusters"`, `"compute/machines"`, `"compute/cpu"`, `"compute/memory"`, `"compute/machines_concurrency"`, `"compute/managed_vm_trial"`, `"agents/turns_concurrency"`, `"agents/sandboxes"`, `"agents/sandboxes_running"`, `"agents/retained_filesystem_lifetime"`, `"codemode/executions"`, `"api/secrets_access"`, `"api/secrets_write"`, `"domain_routing/preview_hostnames"`, `"domain_routing/custom_domains"`, `"source_control/repositories"`.
      - `grant-access`
        - `kind` (enum<string>, required): Available options: `"grant-access"`.
        - `namespace` (string | null, required): Maximum string length: `63`.
        - `permissions` (string[], required): Required array length: `1 - 64 elements`.
      - `reconnect`
        - `kind` (enum<string>, required): Available options: `"reconnect"`.
        - `what` (enum<string>, required): Available options: `"cluster-agent"`, `"connection"`.
      - `add-machine`
        - `kind` (enum<string>, required): Available options: `"add-machine"`.
      - `add-billing`
        - `kind` (enum<string>, required): Available options: `"add-billing"`.
      - `change-input`
        - `kind` (enum<string>, required): Available options: `"change-input"`.
        - `path` (string[], required): Maximum array length: `32 elements`.
      - `retry`
        - `kind` (enum<string>, required): Available options: `"retry"`.
        - `after_seconds` (integer | null, required)
      - `run-agent-install`
        - `kind` (enum<string>, required): Run the command from `POST /v1/clusters/{id}/connector_install` again; it re-applies the ClusterConnector and its updater at one release. Available options: `"run-agent-install"`.
      - `customer-upgrade`
        - `kind` (enum<string>, required): The change needs rights the agent was not granted. Run `command` (a `helm upgrade`, no secret) with an identity that holds `permissions`, or grant them to the agent. Available options: `"customer-upgrade"`.
        - `permissions` (string[], required): Required array length: `1 - 64 elements`.
        - `command` (string, required): Required string length: `1 - 8192`.
  - `last_transition_at` (integer, required): Unix timestamp (seconds) when this condition last changed. Required range: `x >= 0`.
- `last_active_at` (integer | null, required): Last API activity (Unix seconds). Required range: `x >= 0`.
- `created_at` (integer, required): Creation time (Unix seconds). Required range: `x >= 0`.
- `updated_at` (integer, required): Last change (Unix seconds). Required range: `x >= 0`.
- `etag` (string, required): Opaque version token. Send it as `If-Match` on writes.

### 400: The request is malformed.

`application/json`: `ApiBadRequest`

- `_tag` (enum<string>, required): Available options: `"Validation"`.
- `success` (enum<boolean>, required): Available options: `false`.
- `errors` (object[], required): Minimum array length: `1 element`.
  - `code` (integer, required): Machine-readable error code. Required range: `-9007199254740991 <= x <= 9007199254740991`. Example: `7002`.
  - `message` (string, required): Human-readable error message. Example: `"Resource not found"`.
  - `path` (string[]): Field path that caused the error, when applicable. Example: `["body","name"]`.
  - `metadata` (record<string, string>)
- `result` (object, required)

### 403: The credential may not act in this workspace.

`application/json`: `ApiForbidden`

- `_tag` (enum<string>, required): Available options: `"Forbidden"`.
- `success` (enum<boolean>, required): Available options: `false`.
- `errors` (object[], required): Minimum array length: `1 element`.
  - `code` (integer, required): Machine-readable error code. Required range: `-9007199254740991 <= x <= 9007199254740991`. Example: `7002`.
  - `message` (string, required): Human-readable error message. Example: `"Resource not found"`.
  - `path` (string[]): Field path that caused the error, when applicable. Example: `["body","name"]`.
  - `metadata` (record<string, string>)
- `result` (object, required)

### 404: The resource was not found in this workspace.

`application/json`: `ApiNotFound`

- `_tag` (enum<string>, required): Available options: `"NotFound"`.
- `success` (enum<boolean>, required): Available options: `false`.
- `errors` (object[], required): Minimum array length: `1 element`.
  - `code` (integer, required): Machine-readable error code. Required range: `-9007199254740991 <= x <= 9007199254740991`. Example: `7002`.
  - `message` (string, required): Human-readable error message. Example: `"Resource not found"`.
  - `path` (string[]): Field path that caused the error, when applicable. Example: `["body","name"]`.
  - `metadata` (record<string, string>)
- `result` (object, required)

### 409: The request conflicts with existing resource state or immutable intent. | The resource changed since the etag the client sent; the current etag is in the metadata.

`application/json`: `object`

- Any of:
  - `Conflict`
    - `_tag` (enum<string>, required): Available options: `"Conflict"`.
    - `success` (enum<boolean>, required): Available options: `false`.
    - `errors` (object[], required): Minimum array length: `1 element`.
      - `code` (integer, required): Machine-readable error code. Required range: `-9007199254740991 <= x <= 9007199254740991`. Example: `7002`.
      - `message` (string, required): Human-readable error message. Example: `"Resource not found"`.
      - `path` (string[]): Field path that caused the error, when applicable. Example: `["body","name"]`.
      - `metadata` (record<string, string>)
    - `result` (object, required)
  - `PreconditionFailed`
    - `_tag` (enum<string>, required): Available options: `"PreconditionFailed"`.
    - `success` (enum<boolean>, required): Available options: `false`.
    - `errors` (object[], required): Required array length: `1 - 1 element`.
      - `code` (enum<number>, required): Available options: `7006`.
      - `message` (string, required)
      - `metadata` (object, required)
        - `current_etag` (string, required)
        - `{key}` (string)
    - `result` (object, required)

### 422: The request is well-formed but cannot be processed.

`application/json`: `ApiUnprocessable`

- `_tag` (enum<string>, required): Available options: `"Unprocessable"`.
- `success` (enum<boolean>, required): Available options: `false`.
- `errors` (object[], required): Minimum array length: `1 element`.
  - `code` (integer, required): Machine-readable error code. Required range: `-9007199254740991 <= x <= 9007199254740991`. Example: `7002`.
  - `message` (string, required): Human-readable error message. Example: `"Resource not found"`.
  - `path` (string[]): Field path that caused the error, when applicable. Example: `["body","name"]`.
  - `metadata` (record<string, string>)
- `result` (object, required)

### 429: The Workspace or owner sandbox quota has been reached.

`application/json`: `ApiTooManyRequests`

- `_tag` (enum<string>, required): Available options: `"TooManyRequests"`.
- `success` (enum<boolean>, required): Available options: `false`.
- `errors` (object[], required): Minimum array length: `1 element`.
  - `code` (integer, required): Machine-readable error code. Required range: `-9007199254740991 <= x <= 9007199254740991`. Example: `7002`.
  - `message` (string, required): Human-readable error message. Example: `"Resource not found"`.
  - `path` (string[]): Field path that caused the error, when applicable. Example: `["body","name"]`.
  - `metadata` (record<string, string>)
- `result` (object, required)

### 502: An upstream provider failed.

`application/json`: `ApiExternalServiceError`

- `_tag` (enum<string>, required): Available options: `"ExternalServiceError"`.
- `success` (enum<boolean>, required): Available options: `false`.
- `errors` (object[], required): Minimum array length: `1 element`.
  - `code` (integer, required): Machine-readable error code. Required range: `-9007199254740991 <= x <= 9007199254740991`. Example: `7002`.
  - `message` (string, required): Human-readable error message. Example: `"Resource not found"`.
  - `path` (string[]): Field path that caused the error, when applicable. Example: `["body","name"]`.
  - `metadata` (record<string, string>)
- `result` (object, required)

### 503: The service is temporarily unavailable.

`application/json`: `ApiServiceUnavailable`

- `_tag` (enum<string>, required): Available options: `"ServiceUnavailable"`.
- `success` (enum<boolean>, required): Available options: `false`.
- `errors` (object[], required): Minimum array length: `1 element`.
  - `code` (integer, required): Machine-readable error code. Required range: `-9007199254740991 <= x <= 9007199254740991`. Example: `7002`.
  - `message` (string, required): Human-readable error message. Example: `"Resource not found"`.
  - `path` (string[]): Field path that caused the error, when applicable. Example: `["body","name"]`.
  - `metadata` (record<string, string>)
- `result` (object, required)

## Example request

```bash
curl --request PATCH \
  --url 'https://api.akua.dev/v1/sandboxes/sbx_j572abc123def456' \
  --header 'Authorization: Bearer <token>' \
  --header 'if-match: 42' \
  --header 'Content-Type: application/json' \
  --data '{
    "name": "checkout-service",
    "size": "standard",
    "network_policy": {
      "mode": "allow_all"
    },
    "idle_timeout_seconds": 600,
    "labels": {
      "key": "<string>"
    }
  }'
```

## Example response

`200` `application/json`

```json
{
  "id": "sbx_j572abc123def456",
  "workspace_id": "ws_j572abc123def456",
  "name": "checkout-service",
  "state": "PROVISIONING",
  "size": "standard",
  "source": {
    "type": "sandbox",
    "sandbox_id": "sbx_j572abc123def456"
  },
  "network_policy": {
    "mode": "allow_all"
  },
  "idle_timeout_seconds": 600,
  "env": {
    "key": "<string>"
  },
  "labels": {
    "key": "<string>"
  },
  "created_by": {
    "type": "user",
    "id": "<string>"
  },
  "usage": {
    "active_seconds": 123,
    "cpu_seconds": 123,
    "egress_bytes": 123,
    "ingress_bytes": 123
  },
  "conditions": [
    {
      "reason": "agent-offline",
      "severity": "error",
      "message": "<string>",
      "remedy": {
        "kind": "free-capacity",
        "metric": "kaas/clusters",
        "limit": 123,
        "usage": 123,
        "hint": "<string>"
      },
      "last_transition_at": 123
    }
  ],
  "last_active_at": 123,
  "created_at": 123,
  "updated_at": 123,
  "etag": "<string>"
}
```
