> 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/guides/scoped-api-keys.md).

# Scoped API keys

An Orchard API key normally acts as you across your whole organization. A **scoped** key is narrower, safe to hand to CI, a teammate, or a frontend, limited to:

* **specific sandboxes** (`sandbox_uuids`), and/or
* **a tag** (`tag`), every sandbox carrying that tag, *including ones created later*, so you can issue a key once and let it follow a fleet, and/or
* **a capability subset** (`allowed_features`), e.g. `logs` + `files` only.

You can never mint a key more powerful than yourself: capabilities are intersected with your own, and sandbox uuids must be ones you can see.

{% tabs %}
{% tab title="Python" %}

```python
key = orchard.keys.create(
    "ci-logs",
    sandbox_uuids=[sb.uuid],          # or omit for the whole org
    tag="payments",                   # or scope by tag
    allowed_features=["logs", "files"],
    expires_in_days=30,
)
print(key["token"])                   # shown once, store it now
orchard.keys.list()
orchard.keys.delete(key["id"])
```

{% endtab %}

{% tab title="TypeScript" %}

```ts
const key = await orchard.keys.create("ci-logs", {
  sandboxUuids: [sb.uuid],
  tag: "payments",
  allowedFeatures: ["logs", "files"],
  expiresInDays: 30,
});
console.log(key.token);               // shown once
await orchard.keys.list();
await orchard.keys.delete(key.id!);
```

{% endtab %}
{% endtabs %}

## How scope is enforced

Scope is checked on every request against the **live** record, so:

* A key limited to sandbox A gets **404** on sandbox B, the same "not found" you'd get for another tenant's sandbox, so the key can't even probe existence.
* A **tag**-scoped key starts reaching a sandbox the moment it is given that tag.
* A capability the key withholds returns **403** ("this API key is not allowed to use …"), distinct from the 404 above.

Capability keys you can grant include `screen`, `input`, `shell`, `files`, `logs`, `app_install`, `frida`, `proxy.direct`, `proxy.tunnel`, `proxy.mitm`, `snapshots`, `templates`, `terminate`.


---

# 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/guides/scoped-api-keys.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.
