> ## 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.

# Run a command

Starts a command and returns it. With `wait: true` the response comes when the command finished, for at most 60 seconds, and includes its output. Requires `run_commands`. Environment: the sandbox's `env`, then the request's. Commands and file operations need an `ACTIVE` sandbox; on any other state they answer 409.

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

## 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"`.

## Path Parameters

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

## Body

Required.

`application/json`: `RunSandboxCommandBody`

- Any of:
  - `Option 1`
    - `argv` (string[], required): Program and arguments, run without a shell. Required array length: `1 - 256 elements`.
    - `cwd` (string, default "/workspace"): Absolute path inside the sandbox. Required string length: `1 - 4096`. Pattern: `^\/[^\0]*$`. Example: `"/workspace/README.md"`.
    - `env` (record<string, string>)
    - `timeout_seconds` (integer, default 600): Seconds before the command is killed. Default 600. Required range: `1 <= x <= 86400`.
    - `wait` (boolean, default false): Return when the command finished, for at most 60 seconds, with its output. Otherwise return as soon as it started.
    - `stdin` (boolean, default false): Keep standard input open for `:writeStdin`. Default false (empty input).
  - `Option 2`
    - `shell` (string, required): A `bash -lc` command line. Required string length: `1 - 16384`.
    - `cwd` (string, default "/workspace"): Absolute path inside the sandbox. Required string length: `1 - 4096`. Pattern: `^\/[^\0]*$`. Example: `"/workspace/README.md"`.
    - `env` (record<string, string>)
    - `timeout_seconds` (integer, default 600): Seconds before the command is killed. Default 600. Required range: `1 <= x <= 86400`.
    - `wait` (boolean, default false): Return when the command finished, for at most 60 seconds, with its output. Otherwise return as soon as it started.
    - `stdin` (boolean, default false): Keep standard input open for `:writeStdin`. Default false (empty input).

## Response

### 201: Command started

`application/json`: `SandboxCommand`

- `id` (string, required): Sandbox command id (`cmd_...`). Pattern: `^cmd_[A-Za-z0-9]{1,64}$`. Example: `"cmd_j572abc123def456"`.
- `sandbox_id` (string, required): Sandbox id (`sbx_...`). Pattern: `^sbx_[A-Za-z0-9]{1,64}$`. Example: `"sbx_j572abc123def456"`.
- `argv` (string[] | null, required)
- `shell` (string | null, required)
- `cwd` (string, required)
- `timeout_seconds` (integer, required)
- `state` (enum<string>, required): `SUCCEEDED`: exited with code 0. `FAILED`: exited with another code, was killed, or hit its timeout (exit code 124). Available options: `"RUNNING"`, `"SUCCEEDED"`, `"FAILED"`, `"CANCELLED"`.
- `exit_code` (integer | null, required): Set once the command finished.
- `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`.
- `created_at` (integer, required): Start time (Unix seconds). Required range: `x >= 0`.
- `finished_at` (integer | null, required): Finish time (Unix seconds). Required range: `x >= 0`.
- `output` (object | null, required): Captured output, only on the response to a `wait: true` request that finished in time; `null` elsewhere.
  - `stdout` (string, required)
  - `stderr` (string, required)
  - `truncated` (boolean, required): True when the output is longer than the 64 KiB returned here; read it all with `logs:stream`.

### 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 POST \
  --url 'https://api.akua.dev/v1/sandboxes/sbx_j572abc123def456/commands' \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "argv": [
      "<string>"
    ],
    "cwd": "/workspace/README.md",
    "env": {
      "key": "<string>"
    },
    "timeout_seconds": 600,
    "wait": false,
    "stdin": false
  }'
```

## Example response

`201` `application/json`

```json
{
  "id": "cmd_j572abc123def456",
  "sandbox_id": "sbx_j572abc123def456",
  "argv": [
    "<string>"
  ],
  "shell": "<string>",
  "cwd": "<string>",
  "timeout_seconds": 123,
  "state": "RUNNING",
  "exit_code": 123,
  "created_by": {
    "type": "user",
    "id": "<string>"
  },
  "created_at": 123,
  "finished_at": 123,
  "output": {
    "stdout": "<string>",
    "stderr": "<string>",
    "truncated": true
  }
}
```
