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

# Revoke an Agent Vault session

> End a session before it expires so its agent stops getting credentials.

Revoking a [session](https://infisical.com/docs/documentation/platform/agent-vault/sessions) ends it before it expires. Within one [poll interval](https://infisical.com/docs/documentation/platform/agent-vault/proxies#poll-interval) (60 seconds by default), the [proxy](https://infisical.com/docs/documentation/platform/agent-vault/proxies) stops attaching credentials to the agent's requests. You can't reactivate a revoked session, so to give the agent access again, [create a new session](https://infisical.com/docs/documentation/platform/agent-vault/create-a-session.md).

Revoke a session when:

* Its agent finishes, even if the agent fails
* You think its session token leaked, because anyone with the token can call every API in the session's access bundle until the session ends
* The agent no longer needs access, such as a long-running agent you're shutting down

These people and machine identities can revoke a session:

* Admins of the Agent Vault project, for any session in the project
* Members of the project, for their own sessions
* A machine identity, for the sessions it created, including sessions it created [on behalf of a user](https://infisical.com/docs/documentation/platform/agent-vault/sessions-on-behalf-of-users.md)
* Anyone who holds the session's token

## Revoke the session

> [tab] Dashboard
>
> In your Agent Vault project, go to **Sessions**, open the session's menu, and select **Revoke Session**.
>
> If you're an admin of the project, select **All Sessions** to find sessions that other users and machine identities created.

> [tab] CLI
>
> If you started the agent with `infisical agent-vault run --access-bundle`, the CLI revokes the session when the agent exits, including when Docker or systemd stops the agent. To keep the session active after the agent exits, pass `--keep-session`.
>
> To revoke any other session, run [`infisical agent-vault sessions revoke`](https://infisical.com/docs/cli/reference#agent-vault-sessions-revoke) with the session's ID, as your user or as a machine identity:
>
> ```bash theme={"dark"}
> infisical agent-vault sessions revoke <session-id>
> ```
>
> To revoke a session by its token instead, without logging in, leave out the ID. The CLI revokes the session whose token is in `INFISICAL_AGENT_VAULT_SESSION_TOKEN`, or in `--session-token`:
>
> ```bash theme={"dark"}
> infisical agent-vault sessions revoke
> ```
>
> If the session is already revoked or expired, the command still succeeds.

> [tab] API
>
> Call the [Revoke session](https://infisical.com/docs/api-reference/endpoints/agent-vault-sessions/revoke.md) endpoint with the session's ID:
>
> ```bash theme={"dark"}
> curl -X POST https://app.infisical.com/api/v1/agent-vault/sessions/<session-id>/revoke \
>   -H "Authorization: Bearer <access-token>"
> ```
>
> Revoke the session even if the agent fails, for example in a `finally` block or an exit handler. If the agent can run longer than your access token lasts, log in again before you revoke the session.
>
> To revoke a session with its session token instead of an access token, such as from the agent itself, call the [Revoke session by token](https://infisical.com/docs/api-reference/endpoints/agent-vault-sessions/revoke-by-token.md) endpoint:
>
> ```bash theme={"dark"}
> curl -X POST https://app.infisical.com/api/v1/agent-vault/session/revoke \
>   -H "Authorization: Bearer <session-token>"
> ```

> [tab] Python SDK
>
> Call `agent_vault.sessions.revoke` with the session's ID. To revoke the session even if the agent fails, call it in a `finally` block:
>
> ```python theme={"dark"}
> session = client.agent_vault.sessions.create(project_id="<project-id>", access_bundle="<access-bundle-name>", ttl="1h")
> try:
>     run_agent(session.token)
> finally:
>     client.agent_vault.sessions.revoke(session_id=session.id)
> ```
>
> The SDK doesn't renew the client's access token. If the agent can run longer than the access token lasts, log in again before you revoke the session. See the [Python SDK reference](https://infisical.com/docs/sdks/languages/python.md#agent_vault-sessions) for every method.

> [tab] Node.js SDK
>
> Call `agentVault().sessions.revoke` with the session's ID. To revoke the session even if the agent fails, call it in a `finally` block:
>
> ```typescript theme={"dark"}
> const session = await client.agentVault().sessions.create({
>   projectId: "<project-id>",
>   accessBundle: "<access-bundle-name>",
>   ttl: "1h"
> });
>
> try {
>   await runAgent(session.token);
> } finally {
>   await client.agentVault().sessions.revoke(session.id);
> }
> ```
>
> The SDK doesn't renew the client's access token. If the agent can run longer than the access token lasts, log in again before you revoke the session. See the [Node.js SDK reference](https://infisical.com/docs/sdks/languages/node.md#agentvault-sessions) for every method.

## Revoked sessions

* The **Sessions** page shows the session as **Revoked**, and keeps the session so you can still see the access bundle and services the agent had
* You can still [view the session's logs](https://infisical.com/docs/documentation/platform/agent-vault/sessions#view-session-logs) and [change its label](https://infisical.com/docs/documentation/platform/agent-vault/sessions#label-a-session-and-add-metadata)
* Infisical deletes the credentials of the session's [inline services](https://infisical.com/docs/documentation/platform/agent-vault/inline-services.md) right away
* Infisical writes an [audit event](https://infisical.com/docs/documentation/platform/agent-vault/sessions#audit-trail) for the revocation

Revoking a session doesn't remove the [skills](https://infisical.com/docs/documentation/platform/agent-vault/skills.md) that the CLI already installed on the agent's host. To stop agents from using those skills, delete the installed copies.

## Sessions left active

If the agent's machine shuts down mid-run, or your code exits before it revokes the session, the session keeps working until it expires. To limit how long that can last, set the session's [duration](https://infisical.com/docs/documentation/platform/agent-vault/create-a-session.md#duration) a little longer than the agent's longest run, instead of `never`.

## Troubleshooting

> [accordion] A session stays Active after the agent stopped
>
> Nothing revoked the session. This happens if:
>
> * The machine shut down, or the CLI's process was killed, before the CLI could revoke the session
> * Your code exited before it reached the revoke call
>
> Revoke the session on the **Sessions** page, or let it expire.

> [accordion] Revoking a session fails with 401
>
> The access token you sent expired. Log in again to get a new access token, then revoke the session.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.