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

# PAM for AI agents

> Give an AI agent access to your databases and servers without giving it a credential.

AI agents often need privileged access; for example, a coding agent that reads production data to trace a bug, or an agent you built that runs a nightly task against a database. If you put a connection string in the agent's environment, the agent holds a long-lived credential while it reads untrusted input.

Agentic access lets an agent use your PAM [accounts](https://infisical.com/docs/documentation/platform/pam/accounts/overview.md) without ever receiving their credentials. One command opens the accounts the agent can use, gives the agent instructions for reaching them, and starts the agent in a [sandbox](https://infisical.com/docs/documentation/platform/pam/ai-agents/run.md#sandbox):

```bash theme={"dark"}
infisical pam agentic access -- claude
```

You can run any agent this way. The CLI recognizes Claude Code, Codex, and Gemini by name, and an agent you build yourself can read the same instructions from [a file](https://infisical.com/docs/documentation/platform/pam/ai-agents/instructions.md#agents-you-build-yourself).

> [card] [Run an agent](https://infisical.com/docs/documentation/platform/pam/ai-agents/run.md)
>
> Start an AI agent with access to the PAM accounts its task needs.

> [card] [Agent instructions](https://infisical.com/docs/documentation/platform/pam/ai-agents/instructions.md)
>
> Tell an AI agent which PAM accounts it can use and how to reach them.

> [card] [Run unattended](https://infisical.com/docs/documentation/platform/pam/ai-agents/unattended.md)
>
> Run an AI agent as its own machine identity.

> [card] [Review and stop an agent](https://infisical.com/docs/documentation/platform/pam/ai-agents/review.md)
>
> Check what an AI agent did with your accounts and remove its access.

## How it works

The CLI opens one port on `127.0.0.1` for each account the agent can use. The agent connects to a port the same way it connects to any database or server, and the [Gateway](https://infisical.com/docs/documentation/platform/gateways/overview.md) adds the account's credential to the connection:

```mermaid theme={"dark"}
flowchart LR
  subgraph machine["Your machine"]
    direction TB
    subgraph box["Sandbox"]
      AGENT["AI agent<br/>no credentials"]
    end
    CLI["Infisical CLI<br/>one local port per account"]
  end

  GW["Gateway<br/>adds the credential"]
  TARGET[("Your databases<br/>and servers")]
  INF["Infisical<br/>policies, approvals, recordings"]

  AGENT -->|"127.0.0.1:52431"| CLI
  CLI -->|"encrypted tunnel"| GW
  GW --> TARGET
  CLI -.->|"opens the session"| INF
  GW -.->|"records the session"| INF
```

1. The CLI opens the ports and starts the agent
2. When the agent first connects to an account, Infisical checks the role, the duration, and any [approval](https://infisical.com/docs/documentation/platform/pam/access-requests/overview.md) the account requires, then opens a [session](https://infisical.com/docs/documentation/platform/pam/sessions/overview)
3. The Gateway adds the credential to the connection before it reaches the database or server, so the agent never receives the credential
4. Infisical records the session under whoever the run authenticated as, the same way it records a person's session

> [!NOTE]
>
> If the agent never connects to an account, Infisical doesn't open a session for it.

## Who the agent runs as

An agent has no access of its own. It uses the roles of whoever starts the run, and Infisical attributes its sessions and access requests to that user or machine identity:

* **You:** Log in with `infisical login` before you start the agent (for a coding agent that you work with in your terminal)
* **A machine identity:** Give the agent its own identity (for an agent that runs on a schedule or on a server), as described in [Run unattended](https://infisical.com/docs/documentation/platform/pam/ai-agents/unattended.md)


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