# Contain an agent

> Request, approve, verify, and lift an agent quarantine without overlooking failed enforcement.

Canonical page: https://anectico.com/docs/agents/contain-an-agent/


For a single credential, start with [Revoke an agent's access](/docs/agents/revoke-agent-access).

## Contain an agent

Use quarantine to freeze writes reversibly, act on an agent asset or observation key, or require
two-principal approval before disabling credentials. For an emergency affecting a known credential,
[direct revocation](/docs/agents/revoke-agent-access) does not require the quarantine approval flow.

In the product, containment lives at **Govern → Containment**. Requesting and approving are two
separate controls there, and the page refuses to offer you the approval of a request you raised
yourself.

### Approval requires two different principals

A containment requires two different principals. A request changes no credential; approval applies
the containment. The requester cannot approve their own request, including through a script using
the same credential.

`quarantine:request` is granted to every role except viewer, deliberately — sounding the alarm
should not require finding an admin first. `quarantine:approve` is owner/admin-only, because
approving is what disables a production credential; the same scope is required to lift a
containment afterward. Withdrawing a request nobody approved is the one act that sits with the
requester: see [Withdraw a request nobody approved](/docs/agents/contain-an-agent#withdraw-a-request-nobody-approved). See
[Permission scopes](/docs/reference/permissions#organization-ai-and-agents) for both.

### Three actions, and what each one actually does

| Action | What it does | Reversible? |
| --- | --- | --- |
| `freeze_writes` (default) | Strips every write-shaped scope from each credential involved, keeping only the scopes that end `:read`. The original scope set is stashed so a lift restores it exactly. | Yes — the only reversible action |
| `revoke_credentials` | Revokes each credential outright — the same durable revocation [described here](/docs/reference/credential-revocation#revoke). | **No.** There is no un-revoke |
| `kill` | Freezes and then permanently revokes every credential in the approved set. When the target resolves to an agent asset, it also installs a standing ban on minting a declared credential for that agent; a direct API-key target has no agent on which to install that ban. | Only the freeze half; the ban lifts with the containment |

Read `freeze_writes` literally: it removes every scope that is not read-shaped. A typical SDK
ingest key holds only `ingest:write` and nothing else, so freezing it reduces that key to **zero**
scopes. **A frozen ingest key's telemetry stops arriving.** That is the point of freezing an agent's
telemetry credential, not a side effect to route around — if you need the agent's data to keep
flowing while you investigate, freezing that key is the wrong action.

`revoke_credentials` calls the exact same durable revoke as [the CLI revoke command](/docs/reference/credential-revocation#revoke) — same
`401` on the very next request, same permanence. Everything in
[What stops immediately](/docs/reference/credential-revocation#what-stops-immediately), [What finishes rather than stopping](/docs/reference/credential-revocation#what-finishes-rather-than-stopping),
and [What revocation cannot take back](/docs/reference/credential-revocation#what-revocation-cannot-take-back) is equally true of a
quarantine that revokes.

### What a containment names

A target is one of three things, not always a key you already hold:

- an **asset id**, if the agent is in your inventory — resolves to every credential that has
  produced that asset's telemetry
- an **observation key**, for an agent nobody declared — the
  [attribution lookup](/docs/reference/credential-revocation#find-the-key-first-if-you-only-know-the-agent) returns this
- an **API key id** directly, when you already know exactly which credential to stop

The request body must supply **exactly one** of `asset_id`, `observation_key`, or `api_key_id`.
Supplying none or supplying several is a `400`; Anectico never chooses one by priority. `action` may
be omitted, in which case it defaults to `freeze_writes`. If it is present, it must name
`freeze_writes`, `revoke_credentials`, or `kill`; a blank or unknown spelling is a `400` and creates
no containment request.

An API key id is checked against your organization's keys when the containment is **approved**, and
against the **project** the containment is scoped to. A well-formed id that names no key of yours —
one wrong character, a key belonging to somebody else, or one belonging to a different project of
your own — is refused at that point with a `404`, rather than producing a containment that reports
success over a credential it should not reach. Revoking is permanent, so this check runs before the
approval is signed. A key created with `org_wide` belongs to no project and stays reachable from any
of them. The same rules apply to an asset id outside the scope you named.

### Request, approve, verify, lift

```bash
# 1. Request — any member or developer can raise this
curl --fail-with-body \
  -X POST \
  -H "X-Anectico-API-Key: $ANECTICO_API_KEY" \
  -H "Content-Type: application/json" \
  "https://app.anectico.com/api/v1/quarantines" \
  --data '{
    "asset_id": "asset_9f2c...",
    "action": "freeze_writes",
    "reason": "Agent is retrying a failing tool call in a tight loop"
  }'
```

A successful request answers `201`. Its `quarantine.quarantine_id` is what the next three calls act
on, and `quarantine.status` reads `"pending"` — nothing has been enforced yet.

`request_id` is yours to choose, and re-sending the same one returns your existing request instead of
opening a second containment. It is scoped to the person who used it first: if somebody else in your
organization already used that id, you get a `409` telling you the id is taken — and nothing about
their request. Two people running the same runbook need two ids, or one of them will be told to pick
another.

```bash
# 2. Approve — a DIFFERENT principal, holding quarantine:approve. Reusing the
# requester's own key here is refused: the platform can tell from the credential
# that made the request, and rejects an approval that would make the two-person
# rule a formality.
curl --fail-with-body \
  -X POST \
  -H "X-Anectico-API-Key: $ANECTICO_APPROVER_API_KEY" \
  "https://app.anectico.com/api/v1/quarantines/$QUARANTINE_ID/approve"
```

```bash
# 3. Verify — check what actually happened
curl --fail-with-body \
  -H "X-Anectico-API-Key: $ANECTICO_APPROVER_API_KEY" \
  "https://app.anectico.com/api/v1/quarantines/$QUARANTINE_ID"
```

```bash
# 4. Lift — when the incident is over
curl --fail-with-body \
  -X POST \
  -H "X-Anectico-API-Key: $ANECTICO_APPROVER_API_KEY" \
  -H "Content-Type: application/json" \
  "https://app.anectico.com/api/v1/quarantines/$QUARANTINE_ID/lift" \
  --data '{"reason": "Root cause fixed, agent redeployed with a corrected retry budget"}'
```

Lifting also takes `quarantine:approve` — restoring capability to an agent someone decided to stop
is treated as the same grade of decision as stopping it in the first place. A lift restores
whatever a freeze reduced. It does **not** undo a revoke: see
[Three actions](/docs/agents/contain-an-agent#three-actions-and-what-each-one-actually-does), and mint a replacement
credential the normal way once you've lifted.

**A lift frees only what no other containment is still holding.** One key often serves several
agents, so two containments raised against two different agents can land on the same credential.
Lifting one of them leaves that shared credential frozen while the other is still active, and says
so: the credential appears under `quarantine.credentials` with `detail_code`
`held_by_another_quarantine`. Lift the other containment and the credential comes back — whichever
lift is the last to let go is the one that restores it. Without that rule, lifting the first
containment would hand the agent its capability back while the second one still reported it
contained.

Two people lifting two overlapping containments at the same moment is safe. Whichever of the two
ends up last still releases the shared credential, so simultaneous lifts cannot leave an agent
frozen by a containment that no longer exists.

To see everything currently open or historical, `GET /api/v1/quarantines?status=pending` (repeat
`status` for more than one value) lists across your organization, newest first.

### Withdraw a request nobody approved

Not every request should end in a containment. An alarm raised on a hunch that turns out to be a
deploy, a runbook fired twice, a request overtaken by the agent being taken offline anyway — all
leave a `pending` row, and a pending row is not inert: **while a containment is pending, no second
one can be raised against the same agent.** Leaving it there means the next person who genuinely
needs to contain that agent is refused.

```bash
curl --fail-with-body \
  -X POST \
  -H "X-Anectico-API-Key: $ANECTICO_API_KEY" \
  -H "Content-Type: application/json" \
  "https://app.anectico.com/api/v1/quarantines/$QUARANTINE_ID/withdraw" \
  --data '{"reason": "The retry storm was a bad deploy, not the agent"}'
```

**Withdrawing your own request takes only `quarantine:request`** — the scope you used to raise it.
That is deliberate and it is the one place the two containment scopes are not symmetric: a pending
request has enforced nothing, so retracting it hands capability back to nobody, which is the thing
`quarantine:approve` is owner/admin-only to protect. Requiring an admin to clear a row that never had
an effect is how such rows come to be left alone.

**Withdrawing somebody else's takes `quarantine:approve`.** Retracting another person's request
suppresses a containment before a second principal has had the chance to consider it, which is the
same decision as refusing one.

Three things to expect:

- A withdrawal reaches **no credential**, because a pending request never touched one. Nothing is
  frozen, released, revoked or restored by it.
- It only works on a `pending` request. An approved containment is ended with a **lift**, which
  restores credentials; a withdrawal on anything else is refused with `400`.
- The withdrawn request keeps its `request_id`, and re-sending that id returns the withdrawn record
  rather than opening a new containment. **Raising the request again means choosing a new
  `request_id`.**

Like a lift, a withdrawal requires a `reason`, and the record stays: `status` reads `"withdrawn"`,
with `withdrawn_by`, `withdrawn_at` and `withdraw_reason`. "Somebody asked to stop this agent and
then thought better of it" is a fact an incident review wants, and deleting the row would lose it.

### Reading the status

`quarantine.status` is `"pending"` (requested, nothing enforced), `"active"` (approved and
enforced), `"lifted"` (released after having been enforced — the record stays, because "this agent
was stopped for six hours last Tuesday" is exactly the fact an incident review needs), or
`"withdrawn"` (retracted before anyone approved it, so it was never enforced at all).

`"lifted"` and `"withdrawn"` are separate on purpose. Both are endings, and they say opposite things:
one agent was stopped and let go, the other was never stopped. A count of your containments should
not include the ones that never happened.

A quarantine that has ended also carries **why**: `lift_reason` on a lifted one, `withdraw_reason` on
a withdrawn one, beside the `lifted_by`/`lifted_at` and `withdrawn_by`/`withdrawn_at` pair.

Each credential a quarantine resolved to is reported individually, under `quarantine.credentials`,
with its own state — one containment can legitimately freeze one key and find a second already
revoked, and a single rolled-up answer would misreport the pair. **`verified` means the platform's
own credential store now denies the credential** on its very next request — that is a fact about
the credential, not a promise that no more telemetry has arrived, because confirming an absence
would mean waiting and guessing how long is long enough.

**`unknown` is not a failure — it is an honest answer to a question containment cannot always fully
close.** You will see it when:

- some of the target's recorded telemetry carried no credential the platform can revoke at all — a
  signed-in person's dashboard session, or a sighting recorded before this feature existed to track
  which credential produced it
- the target resolved to no credentials at all, in which case reporting `verified` would claim to
  have revoked nothing while sounding like containment succeeded
- a credential this containment named was **already frozen** by an earlier one, so this containment
  changed nothing about it (`detail_code` `already_contained`). The credential is contained — and it
  stays contained until every containment naming it has been lifted — but the effect belongs to the
  earlier one, and claiming it here would be this containment taking credit for another's work
- the credential no longer exists in your organization (`detail_code` `no_such_credential`), which
  is a different fact from having contained it

`quarantine.unenforceable_sightings` tells you how many sightings fall into the first case. A
non-zero count is not a bug report: it means some of what this agent did did not arrive on anything
the platform can take away, and the honest status for that is `unknown`, never a false `verified`.

### `kill` and its third clause — read this before you rely on it

**`kill` also stops a new key being minted for the agent, but only for keys that say which agent
they are for.**

A key can be minted with a **declaration**: the id of the agent it is being created for. Pass
`--agent` to `anectico agent bootstrap` or `anectico apikey create`, or send `"agent_asset_id"` in
the body of `POST /api/v1/account/api-keys`. A declared key gets two things an undeclared one does
not:

- while a `kill` containment is live on that agent, minting another key for it is **refused** — a
  `400` whose `details.reason` is `AGENT_MINT_BANNED` and whose `details.asset_id` names the agent,
  so you can find the containment that refused you;
- a containment can reach it **before it has ever been used**. Anectico normally learns which key
  belongs to which agent by watching telemetry, so a key you minted and have not deployed yet is
  invisible to that. A declared key is not.

The declaration has to name a **real agent in the same project as the key**. An id that matches
nothing, one belonging to another project, or one naming something that is not an agent is refused
with a `400` before any key is created — so a declaration is a fact about your inventory rather than
a string you typed. Two consequences worth planning around: declare an agent only once it appears in
`anectico fleet list` (a brand-new agent has no id until its first telemetry arrives, which is why
`anectico agent bootstrap` warns rather than refusing when `--agent` is omitted), and an
**org-wide** key cannot carry a declaration at all, because an agent belongs to exactly one project.

A key minted for that agent **while the kill is being applied** does not slip through. The ban and
the list of keys it acts on are taken as one act, so a mint either lands before the ban — in which
case the same `kill` revokes it, and its row in the containment says `credential_minted_during_kill`
— or it arrives after and is refused.

**A key that declares no agent is outside both.** Anybody in your organization who can create API
keys can still create a plain one and give it to the agent you killed, and nothing refuses that
mint. The first telemetry from that key supplies the missing link: Anectico then raises a critical
review signal naming the non-secret key id, the killed agent, the active containment, and the first
and latest sighting times. It raises one row per key and containment, not one per span.

That signal appears in the review queue, sends opening and clearing notifications, and can be
targeted by an alert rule using the `review_signals` source. It contains nothing and revokes nothing;
a person still decides whether to revoke the key. Repeated sightings do not send another opening.
Revoking it or lifting the named containment closes the row. The window before first telemetry remains real, so if your recovery plan
depends on "nobody can re-provision this agent", the process control is still yours: **mint agent
keys with `--agent` so the ban can bind, and treat `api_key:write` as the permission that can undo a
containment.**

Every `kill` tells you which case you are in. Its enforcement points include one for the mint path:

| What you see | What it means |
| --- | --- |
| `mint_ban_declared_only` | The ban is in force for keys that declare this agent. It cannot stop an undeclared key. |
| `mint_ban_no_asset` | **No ban was installed at all** — the containment named an API key directly, or an agent Anectico has not yet built an inventory entry for. |
| `enforcement_failed` | The ban could not be installed. [Re-enforce the containment](/docs/agents/contain-an-agent#if-part-of-a-containment-failed-re-enforce-it) — do not lift it. |

Lifting the containment restores minting. If two containments name the same agent, both have to be
lifted — and the lift tells you when the ban survives because another one still holds it. A lift of
a containment whose ban was never installed says `nothing_to_restore` rather than
`quarantine_lifted`, so the record keeps saying that the third clause was never in force.

The inventory lifecycle follows the same cover-set rule. Two different targets can resolve to the
same agent; lifting either one leaves that agent `quarantined` while the other containment is active,
and the last lift restores the lifecycle state the agent had before the first containment began.

**If a lift fails partway, run it again.** Lifting is idempotent: a repeated lift on a containment
that has already been released finishes whatever the first attempt did not, rather than refusing
you. Retrying is always the right first move.

### If part of a containment failed, re-enforce it

A containment is recorded before anything is applied, so an approval can succeed while one of its
effects does not — a credential that could not be reached, or a mint ban that could not be
installed. The containment then reads `active` with a `failed` row inside it, which is the truth and
not a bug.

**Do not lift it to fix it.** Lifting restores the credentials and re-opens the mint path, which for
a `kill` re-opens the agent in order to repair the thing that was meant to keep it shut. Re-enforce
instead:

```bash
curl --fail-with-body \
  -X POST \
  -H "X-Anectico-API-Key: $ANECTICO_API_KEY" \
  "https://app.anectico.com/api/v1/quarantines/$QUARANTINE_ID/reenforce"
```

It re-runs only what is recorded as failed, under the approval the two principals already made — it
approves nothing new and needs no second person. `retried` in the response says how many things were
re-attempted; `0` means there was nothing left to repair, which is a success rather than an error. It
takes the same permission as approving and lifting.

### A contained key cannot be edited around

While a key is frozen, its scopes cannot be changed by the ordinary key-editing route: a
`PATCH /api/v1/account/api-keys/{id}` that carries scopes is refused with a `400` whose message
names the containment. Renaming still works.

This is deliberate, and it matters because the two authorities differ. Editing a key's scopes is
something every member and developer can do; approving and lifting a containment is owner/admin
only. Without the refusal, anyone who could edit a key could hand a stopped agent its write scope
back on the next request — with nothing linking that act to the containment somebody else approved.
It also keeps the lift honest: the original scope set is stashed when the freeze happens, so a
change made while frozen would either be overwritten by the lift or, worse, silently re-granted by
it. Lift the containment first, then edit.

A frozen key is visible as frozen. `GET /api/v1/account/api-keys` reports `frozen: true` with a
`frozen_at` timestamp for every contained key, so a key whose scope list has shrunk is explained
rather than mysterious. It is not the same as `revoked`: a frozen key still authenticates, and a
revoked one is gone for good.
