Credentials should never reach the model
Summary
Placing API credentials directly within an AI agent's process, such as environment variables, config files, or prompts, creates a critical security vulnerability. This practice exposes raw, long-lived tokens to prompt injection attacks, allowing crafted inputs to instruct the agent to exfiltrate credentials to an attacker. The fundamental principle is that raw credentials must never enter the model process. Instead, a "broker" pattern is advocated, where a trusted broker sits between the agent and the external resource. The agent sends a scoped capability request to the broker, which holds the real token, enforces access scope, and attaches authentication at the boundary. This ensures the model never sees the actual key, transforming potential credential theft into, at worst, an attempted misuse limited by predefined scope and policy. Crucially, all outbound calls carrying credentials must be routed through this broker, preventing agents from bypassing the system by fetching or using tokens directly.
Key takeaway
AI Security Engineers or MLOps Engineers deploying agents must ensure their code never directly accesses raw downstream API tokens. If your current setup allows agents to touch real credentials, prompt injection becomes a direct path for credential exfiltration, not merely agent misbehavior. Implement a credential broker pattern to isolate secrets, routing all outbound calls through it. This transforms the risk from token theft to, at worst, a scoped misuse that your policies can still catch.
Key insights
Never allow raw credentials to enter the AI model process to prevent prompt injection-based exfiltration.
Principles
- The raw credential never enters the model process.
- The model is the untrusted part.
- Fail closed on credential access.
Method
Implement a broker between the agent and resource; the agent requests capabilities, the broker holds the token, enforces scope, and attaches authentication at the boundary, returning only the result to the model.
In practice
- Route all credentialed outbound calls through a broker.
- Block direct network egress for agents.
- Withhold broad tokens from agents; use broker for calls.
Topics
- AI Agent Security
- Prompt Injection
- Credential Management
- Broker Pattern
- API Security
Best for: AI Engineer, MLOps Engineer, AI Security Engineer
Related on AIssential
See Counsel's argued verdicts on the open AI decisions leaders are weighing →
Editorial summary, takeaway, and curation by AIssential. Original article published by Blog | DataRobot.