> For the complete documentation index, see [llms.txt](https://docs.orchard.airoverflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.orchard.airoverflow.com/reference/errors.md).

# Errors & close codes

## REST errors

A non-2xx response raises `ApiError` (both SDKs). It carries `status` and `detail`; the message is mapped to something actionable.

| Status  | Meaning                                                                                  |
| ------- | ---------------------------------------------------------------------------------------- |
| **401** | The API key is invalid or expired.                                                       |
| **403** | You (or your scoped key) may not use this capability/role.                               |
| **404** | No such sandbox, or your key is scoped and may not reach it (existence is never leaked). |
| **409** | Conflict, e.g. resizing a running sandbox, or a duplicate name.                          |
| **4xx** | Validation error; read `detail`.                                                         |

```python
from orchard_sdk import ApiError
try:
    sb.edit(cpu=99)
except ApiError as e:
    print(e.status, e.user_message)
```

```ts
import { ApiError } from "@orchard/sdk";
try { await sb.edit({ cpu: 99 }); }
catch (e) { if (e instanceof ApiError) console.log(e.status, e.message); }
```

## Selector errors

`orchard.sandbox(sel)` raises `SelectorError` when a selector matches zero or more than one sandbox (the message lists the candidates).

## WebSocket close codes

A channel that closes with one of these raises `ChannelClosedError` (with `.code`):

| Code     | Meaning                                |
| -------- | -------------------------------------- |
| **4401** | Unauthenticated (bad/missing token).   |
| **4403** | Forbidden (capability or role denied). |
| **4404** | Unknown sandbox / node / job.          |
| **4502** | The node agent was unreachable.        |

A normal end-of-stream (code 1000/1001) simply ends the iteration, no error.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.orchard.airoverflow.com/reference/errors.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
