Keep credentials out of the agent’s process boundary, then broker access at the control layer so the agent never sees the reusable secret. That reduces the impact of prompt injection, malicious tool output, and supply-chain abuse because the runtime cannot exfiltrate what it cannot read. Scoping still matters, but placement is the first control.
Why This Matters for Security Teams
AI coding agents are not just another application runtime. They can read repositories, call tools, write files, and chain actions faster than a human can review them. If a reusable secret is present in the process boundary, the agent can be tricked into exposing it through prompt injection, malicious tool output, poisoned dependencies, or overbroad logging. That is why the control question is not only whether a secret is scoped, but whether it is ever exposed to the agent at all.
Current guidance from OWASP Agentic AI Top 10 and NHIMG research on Analysis of Claude Code Security points in the same direction: reduce direct secret exposure, then constrain what the agent can request at runtime. The distinction matters because static IAM policies are designed around known human workflows, not autonomous tool use. In practice, many security teams only discover the problem after an agent has already echoed a token into a chat log, commit, or shell history.
How It Works in Practice
The most reliable pattern is to keep secrets outside the agent process and broker access through a control layer that issues narrowly scoped, short-lived credentials only when needed. That usually means replacing static API keys with workload identity, then using a secret broker, token exchange service, or vault-backed gateway to mint task-specific access. The agent authenticates as a workload, not as a person, and it receives only the minimum privilege needed for a single action.
That model aligns with OWASP Non-Human Identities Top 10 and the NIST AI Risk Management Framework, both of which reinforce least privilege, traceability, and runtime governance. In an agentic workflow, the control plane should evaluate policy at request time, not pre-authorise broad access up front. That is where intent-based or context-aware authorisation becomes useful: the agent asks for a capability, the policy engine checks task context, repository sensitivity, tool risk, and environment state, then issues a short-lived token or rejects the request.
- Use JIT credential brokering so secrets are ephemeral and revoked on completion.
- Prefer workload identity such as OIDC-bound tokens or SPIFFE-style identities over shared static keys.
- Store credentials in a broker or vault, not in prompts, environment files, source code, or agent memory.
- Log the request for access, but redact the secret itself from telemetry and debug output.
- Separate read, write, and deploy permissions so the agent cannot chain tools into privilege escalation.
NHIMG’s Ultimate Guide to NHIs — Static vs Dynamic Secrets and the Guide to the Secret Sprawl Challenge both reinforce the operational point: once a reusable credential reaches an autonomous toolchain, revocation becomes damage control rather than prevention. These controls tend to break down in developer environments that allow unrestricted shell access, local config files, or shared CI variables because the agent can still discover credentials through side channels.
Common Variations and Edge Cases
Tighter secret isolation often increases friction for developers and platform teams, so organisations must balance speed against control depth. There is no universal standard for this yet, but current guidance suggests that the most sensitive agents should receive the least durable credentials and the narrowest tool surface, even if that adds broker latency or additional approval steps.
One common edge case is legacy build pipelines that still rely on long-lived environment variables. Another is multi-agent systems where one agent provisions tools for another, creating hidden trust chains. In those environments, policy has to be explicit about which agent may request which capability, and whether delegation is allowed at all. The breach pattern in Amazon Q AI Coding Agent Compromised shows why that matters: if an agent can be induced to execute untrusted instructions, secret placement becomes the first line of defence, not the last.
For teams mapping this to broader controls, the practical test is simple: can the agent complete its task without ever learning the reusable secret? If the answer is no, the design is still too permissive. In the current state of practice, the safest pattern is to treat agent credentials as disposable capabilities, not durable identities.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Agentic AI Top 10, OWASP Non-Human Identity Top 10 and CSA MAESTRO address the attack and risk surface, while NIST AI RMF and NIST Zero Trust (SP 800-207) set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Agentic AI Top 10 | A2 | Covers prompt injection and unsafe tool use that can expose secrets to agents. |
| OWASP Non-Human Identity Top 10 | NHI-03 | Addresses insecure secret handling for non-human identities and service workloads. |
| CSA MAESTRO | T1 | Focuses on agentic threat modeling, including tool abuse and credential exposure paths. |
| NIST AI RMF | Supports governance and runtime risk management for autonomous AI systems. | |
| NIST Zero Trust (SP 800-207) | PR.AC-4 | Zero trust requires per-request verification instead of implicit access for agents. |
Assign ownership, monitor runtime behaviour, and enforce risk-based controls for each agent task.
Related resources from NHI Mgmt Group
Deepen Your Knowledge
Reviewed and updated by the NHIMG editorial team on August 11, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org