
Security patterns
Secrets don't belong in prompts, configs, or repos. Scoping, separation, traceability, rotation, and revocation for agent secrets.
AI agents rely on secrets to do anything useful. To reconcile invoices, an agent needs a token for the ERP. To resolve a ticket, it needs a key for the IT service desk. To enrich a lead, it needs credentials for the CRM. A secret is any sensitive value that unlocks a system: an API key, an OAuth token, a database password, a signing key, a service account credential, or a webhook secret.
Secrets are often treated as an implementation detail—something to wire up once and forget. For AI agents, that framing is dangerous. A secret is not plumbing; it is a governance boundary. An agent holding a powerful secret becomes a powerful actor, and the blast radius of a leaked or over-scoped credential is exactly the blast radius of the agent that holds it.
This post lays out how to handle agent secrets in a way that stays defensible as the number of agents grows: where secrets must never live, and the disciplines—scoping, separation, traceability, rotation, revocation, and human access control—that keep them under control.
The core rule: secrets live in a secrets manager and are fetched at the moment of use—never embedded in the agent's prompt, configuration, or code. Everything else in this post follows from treating the secret as something the agent borrows, not something it owns.
The first discipline is keeping secrets out of the places they tend to drift toward. With agents, those places multiply because so much of an agent's behavior is expressed as text—and text gets logged, copied, and shared.
The alternative is straightforward: store secrets in a secure secrets management system and have the agent retrieve them only when needed, ideally through a broker that injects the credential into the outbound call without exposing the raw value to the agent's reasoning loop at all. The agent should know it can reach the payroll system; it should not know the payroll system's password.
An agent should never receive a secret that unlocks more than it needs. Broad credentials are convenient to issue and catastrophic to lose. Scoping is the practice of issuing the narrowest credential that still lets the agent do its job.
Consider a procurement agent that reconciles supplier statements against purchase orders. Its work is read-only across two systems. There is no reason for its credential to permit creating vendors, approving payments, or touching anything outside the procurement domain. A scoped token might look like:
scopes:
- purchase_orders:read
- supplier_statements:read
resources:
- region: eu-west
- business_unit: procurement
expires_in: 3600sScoping operates on several axes at once: which actions the credential permits, which resources it covers, and how long it remains valid. A short-lived, narrowly scoped token that an attacker captures is far less useful than a long-lived admin key. When you cannot avoid issuing a powerful secret, treat it as an exception that requires explicit justification and review—not the default.
Development, staging, and production agents must use different credentials. A test agent should never hold a production secret. This sounds obvious, yet it is one of the most common failures, because the easiest way to make a flaky integration work in staging is to point it at the credential that already works in production.
Imagine a data-analytics agent under development. An engineer is iterating on its prompts and tool calls, and the agent occasionally misfires—running an unintended bulk export or a heavy query. If that development agent holds the production warehouse credential, a debugging session can corrupt or exfiltrate live customer data. With separated credentials, the worst case is a mess in a sandbox.
Separation also makes traceability honest. When environments share a secret, you cannot tell from the credential alone whether an action came from a tested production agent or an experimental one. Distinct credentials per environment—and, where it matters, per agent—keep the boundaries legible.
When something goes wrong, the question is always the same: which agent used which secret, when, and to do what. If a secret is shared across many agents, or if access is anonymous, that question has no answer—and an investigation stalls before it starts.
Traceability requires that every secret retrieval and every credentialed action be attributable to a specific agent identity. Each call should record:
With that record in place, a legal team investigating an unexpected contract export can trace it to a single agent, a single token, and a single moment—rather than to a shared service account that a dozen systems quietly reuse.
Secrets should not live forever. Rotation—replacing a credential with a new one on a schedule—limits how long an exposed secret stays useful and forces teams to keep credential hygiene healthy rather than letting keys accumulate quietly for years.
The challenge with agents is that rotation must be invisible to running work. If a sales-operations agent is mid-workflow when its CRM token rotates, the rotation should not break it. This is why short-lived, automatically reissued credentials are preferable to long-lived static keys: the agent requests a fresh token each time it needs one, and rotation becomes a property of the system rather than a manual chore someone forgets.
In practice: a credential that is rotated daily and automatically is more secure and less operationally painful than one that is rotated "quarterly" in theory and never in fact. Automation is what makes good rotation policy survive contact with real teams.
Rotation is routine; revocation is the emergency lever. When an agent is retired, compromised, or no longer needs a credential, that credential must be removed—immediately and completely.
Revocation is where governance most often fails, because retiring an agent rarely feels urgent. A recruiting agent gets replaced by a newer version; the old one is switched off, but its service account credential is never revoked. Months later, that dormant credential is still valid—an invisible access path into the HR system that no one is monitoring and no one owns.
Effective revocation has two properties. It must be fast—a single action that cuts off access, not a multi-team ticket. And it must be complete—every credential an agent held is accounted for and removed, which only works if you knew which credentials the agent held in the first place. Revocation is the payoff for the scoping, separation, and traceability disciplines that came before.
Not every person who manages an agent should be able to see its raw secrets. The ability to grant, approve, or revoke access is a different privilege from the ability to read the credential itself—and conflating the two needlessly widens the circle of people who could leak a key.
A platform owner may need to authorize that a finance agent can reach the ledger, and a security reviewer may need to confirm the scope is appropriate. Neither of them needs to view the underlying token. A well-designed secrets layer lets people operate on access as a policy decision while the raw value stays sealed inside the vault.
The fewer humans who ever touch the raw secret, the fewer ways it can escape. For most agent credentials, the right number of people who can read the value is zero.
These disciplines are not independent checkboxes—they reinforce each other. A useful way to see how they fit together is to follow a single credential through its life. Suppose an IT operations agent needs to read alerts from a monitoring system and acknowledge incidents.
alerts:read and incidents:acknowledge—nothing that can delete data or change configuration.None of these steps is exotic. What makes them work is that they are defaults of the platform rather than habits an individual engineer is expected to remember for every agent. When secret handling is built into how agents are provisioned, doing the right thing is the path of least resistance.
Secrets are the difference between an agent that can read a dashboard and one that can move money. They deserve to be treated as a control surface, not as configuration. Keep them out of prompts, configs, and repos. Scope them narrowly. Separate them by environment. Trace every use. Rotate them on a schedule. Revoke them the moment they are no longer needed. And keep the raw values out of human hands wherever you can.
Managing an agent's secrets well is one of the most direct ways to control what the agent can actually do. A powerful secret makes a powerful actor—so the discipline applied to the credential is, in practice, the discipline applied to the agent.