Say a support agent runs in a container. It summarizes tickets with a hosted model, looks up orders in a database, reads attachments from object storage, and replies through a SaaS help desk. The quick setup puts a model-provider key, a database password, a cloud access key, and a help-desk token in environment variables. Then a prompt-injected ticket persuades the agent to run env and paste the output into a reply.
Credential isolation for an application like this is managed in several places. Cloud workload identity (an IAM role, an attached service account, a managed identity) decides which cloud credential the compute receives and removes long-lived cloud keys. A secrets manager holds the database password and SaaS tokens and decides which identity may read them. A broker, proxy, or tool server outside the agent’s process holds those values and makes the call. Per-user delegation decides whose authority the call carries.
The first two don’t keep a credential away from code running on the same compute, and the cloud providers say so. AWS notes that all applications on an EC2 instance share the same role. Microsoft says that all code running on a virtual machine can request tokens for its managed identities. Google warns that any process that can query the metadata URL has access to all of its values. Our position: run the model’s generated code and tool calls in a sandbox that holds no credential and can’t reach a credential endpoint, and let a separate component holding the credentials perform specific, named operations.
Compare where the credential lives
Moving a credential out of the agent’s process stops the agent from copying it. An injected agent can still ask the new holder for anything it’s willing to do, so no row has an empty last column.
| Where the credential lives | Who can read or use it | What a prompt-injected or compromised agent process could still do |
|---|---|---|
| Long-lived key in an environment variable, config file, or image | Every process in the container, plus logs and debugging tools that capture the environment | Print or send the key, then use it from anywhere until someone rotates it |
| System prompt or other model context | The model, plus anyone who can get it to repeat its context, plus transcripts and traces | Reveal the value in an answer, a tool argument, or a log line |
| Workload identity attached to the agent’s own compute | Any code on that instance, task, or VM that can reach the credential endpoint | Call every API the identity permits; copy temporary credentials and use them elsewhere until they expire, unless use is restricted to the workload’s network |
| Secrets manager, fetched by the agent’s own process | The agent’s identity, then anything that can read that process’s memory, environment, or logs | Fetch every secret that identity can read and handle the plaintext |
| Broker or credential-injecting proxy outside the sandbox | The broker’s process and identity | Request any operation, destination, or argument the broker’s rules accept, and read the responses |
| Remote MCP server or tool gateway holding the downstream credential | The server; the client holds only a token issued for that server | Invoke any tool the token’s scopes and the server’s own checks allow |
OWASP’s entry on system prompt leakage says credentials and connection strings shouldn’t be in the system prompt, and recommends externalizing such information “to the systems that the model does not directly access.” The bottom two rows do that, and they need rules of their own because they become what the injected agent talks to.
Cloud workload identity on AWS, Google Cloud, and Azure
On AWS, an IAM role attached through an instance profile supplies temporary credentials through instance metadata, and AWS updates them automatically. That removes access keys from code, but every application on the instance shares the role. ECS task roles give each task its own role, and the ECS task role documentation is blunt: “Containers are not a security boundary and the use of task IAM roles does not change this.” On EC2, ECS Managed Instances, and ECS Anywhere, containers can potentially reach other tasks’ credentials and the instance role, so AWS recommends blocking container access to instance metadata. You can also require IMDSv2 session tokens.
On Google Cloud, code on a resource with an attached service account gets short-lived access tokens from the metadata server. Avoid service account keys, which by default don’t have an expiry time and stay valid until you delete them. On GKE, Workload Identity Federation for GKE gives workloads distinct identities instead of the node’s service account, which “is shared by all workloads deployed on that node.” Workloads outside Google Cloud can use Workload Identity Federation instead of keys, with attribute conditions restricting which external identities may authenticate.
On Azure, managed identities let code obtain Microsoft Entra tokens without anyone handling a credential. Microsoft’s best-practice page spells out the consequence: someone who can execute code on a Logic App can use its identity’s storage permissions without direct access to the storage account. It also notes that managed identity tokens are cached for around 24 hours, so group or role membership changes can take hours to apply.
In all three clouds the identity belongs to the compute, and generated code running there inherits it. We’d give the agent’s sandbox no cloud identity, or one limited to what generated code genuinely needs, and attach the useful identity to the broker.
What fetching from a secrets manager does and does not isolate
AWS Secrets Manager replaces hard-coded credentials “with a runtime call to the Secrets Manager service” and supports rotation. Azure Key Vault serves secrets by URI to callers authenticated through Microsoft Entra ID, with optional access logging. Google Secret Manager uses IAM, and its best practices suggest secret-level bindings and data access logs for AccessSecretVersion.
That takes secrets out of source code and images, and gives you one place to grant, rotate, and audit access. The plaintext still lands in whichever process fetches it.
How the value arrives matters too. When ECS injects a Secrets Manager secret as an environment variable, the value arrives when the container starts and isn’t refreshed after rotation. The same page notes: “Applications that run on the container and container logs and debugging tools have access to the environment variables.” Google’s best-practice page recommends calling the Secret Manager API directly over filesystem or environment delivery, citing debug endpoints and dependencies that log the environment, while noting that some integrations, such as serverless ones, may pass secrets those ways.
So the question for an AI application is which process calls GetSecretValue, AccessSecretVersion, or the Key Vault secret endpoint. If it’s the agent’s own process, injected code can call it too.
You can also restrict where a secret can be read from. Secrets Manager’s resource-based policy examples include one that denies GetSecretValue unless the request arrives through a named VPC endpoint. Here it is with placeholders:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "RestrictGetSecretValueToBrokerEndpoint",
"Effect": "Deny",
"Principal": "*",
"Action": "secretsmanager:GetSecretValue",
"Resource": "*",
"Condition": {
"StringNotEquals": {
"aws:sourceVpce": "<BROKER_VPC_ENDPOINT_ID>"
}
}
}
]
}
The broker’s identity still needs an allow, and AWS warns that other AWS services reading the secret must also come through the VPC or be denied. On Azure, the Key Vault firewall is disabled by default and can be limited to selected networks or private endpoints, though its rules apply to data-plane operations only. On Google Cloud, VPC Service Controls addresses access from unauthorized networks using stolen credentials.
Put a broker or credential-injecting proxy outside the sandbox
The agent’s sandbox gets a network path to one internal endpoint. Behind it, a broker process with its own identity fetches the secret, checks the request, attaches the credential, sends the call, and returns the response. The sandbox never sees the value.
In the support example, the broker might expose “post a reply to ticket N” and “read order M,” holding the help-desk token, the database password, and the model-provider key. An injected agent could still post a bad reply to a ticket it’s allowed to touch. It couldn’t print the help-desk token, because it never had it.
Our sandbox security guide makes the point that a broker accepting arbitrary destinations or commands just relocates the problem. A credential-injecting proxy has a sharper version of that failure. If it adds the help-desk token to any outbound request, an injected agent can send a request to a host it controls and receive the token in the headers. Bind each credential to its intended destination, method, and path, and refuse everything else.
In a design review we’d also check:
- How the broker identifies the caller. A short-lived session token works if only the broker accepts it and it expires with the run.
- Responses and error messages, which can echo credential material into the sandbox.
- Broker logs, which should record caller, destination, and decision without the credential value.
- Bypass paths around the broker. If network policy doesn’t block the metadata addresses and direct internet access, the broker is optional. Our no-egress CI guide covers testing that boundary.
Let the MCP server or tool gateway hold the credential
A remote MCP server can play the broker’s role. The client authenticates to the server, the server holds the downstream credential, and the model sees only tool names, arguments, and results. That depends on the server refusing to reuse the client’s token. The MCP security best practices state that “MCP servers MUST NOT accept any tokens that were not explicitly issued for the MCP server.” Our MCP OAuth article covers the audience, scope, and passthrough tests for that relationship.
Local servers are a different case. The same MCP guidance tells clients to warn users that MCP servers run with the same privileges as the client, and to sandbox them. A local server holding a SaaS token on the same machine and account where a coding agent runs commands may leave that token within the agent’s reach. Run it under a separate account or sandbox, or deploy it remotely.
Per-user delegated tokens or one shared service identity
Apart from where a credential lives, decide whose authority it carries. OWASP’s Excessive Agency entry lists an extension that “accesses downstream systems with a generic high-privileged identity” as a risk. Its prevention guidance includes tracking user authorization, OAuth with the minimum scope required, and “authorization in downstream systems rather than relying on an LLM to decide if an action is allowed or not.”
A shared service identity is one credential to store and rotate, but every user of the agent can reach whatever it reaches, so the broker or MCP server must check each user against each record. A per-user delegated token lets the downstream service apply its own permissions, at the cost of storing and refreshing one token per user. If you exchange tokens, RFC 8693 separates delegation, where the actor “still has its own identity separate from” the user, from impersonation, which changes what your audit trail can show. Our MCP identity passthrough guide compares the ways an MCP server can obtain a per-user downstream token and the tests to run on each.
We’d use delegated tokens when the agent acts on a person’s data, and a narrow service identity for system work with no user behind it, such as a scheduled indexing job. In both cases the broker or server stores the token.
Checks to verify the agent holds no credential
Run these in a test environment with synthetic secrets and test identities. Issue each command through the agent’s own code or tool path, because that’s the path a prompt injection would use.
- List environment variable names without values:
env | cut -d= -f1 | sort. None should hold a long-lived secret. Also review variables that point at a credential file or endpoint, which hold no secret but give the process a way to get one. - Look for credential files in the AWS SDK default file paths (
~/.aws/credentials,~/.aws/config), Google’s Application Default Credentials file ($HOME/.config/gcloud/application_default_credentials.json), and anythingGOOGLE_APPLICATION_CREDENTIALSnames. Check mounted volumes and the workspace for key and.envfiles. - Test TCP reachability on port 80 from the sandbox to
169.254.169.254, the plain-HTTP metadata address in the AWS, Google, and Azure docs. Where IPv6 is enabled, add AWS’sfd00:ec2::254and Google’sfd20:ce::254. On ECS on EC2, add the task-credential address169.254.170.2from the ECS task role setup. Use a plain connection probe like the one in our no-egress guide without requesting a token, and run it from the broker host as a positive control. - Store a synthetic canary credential with a unique marker for a test integration. Run a normal task, a failing call, a retry, and a prompt asking the agent to show its configuration. Export application and broker logs, traces, model request and response logs, transcripts, tool outputs, and error reports, then search them:
grep -rF -- "<CANARY_MARKER>" <EXPORTED_LOG_DIR>. The marker should appear nowhere outside the secrets manager. - In a test account, try a test credential from a host outside the intended network, with a request from inside as the positive control. Expect a recorded denial. On AWS, the condition keys
aws:Ec2InstanceSourceVpcandaws:SourceVpccan tie EC2 role credentials to the VPC they were delivered to, for requests that go through a VPC endpoint. GuardDuty’s credential exfiltration findings report EC2, ECS task, and Lambda credentials used elsewhere, without blocking them, and stop for a remote source GuardDuty has learned as expected. On Azure, Conditional Access for workload identities can block service principals outside known IP ranges, but it requires Workload Identities Premium and doesn’t cover managed identities. For those, use resource-side rules such as the Key Vault firewall. - Remove a permission from the broker’s identity and measure how long the next call takes to fail. On Azure, permissions granted through group or app-role membership can lag for hours because of the token cache described above; Microsoft suggests assigning permissions directly to a user-assigned identity when that delay matters.
Keep the command, identity, source, time, and result for each check, and rerun them when the sandbox image, network policy, broker rules, or identity assignments change. We’d accept the design when the sandbox holds no long-lived secret anywhere we looked, can’t reach a credential endpoint, and the broker’s credentials fail from outside their network. After that, the remaining exposure is the list of operations the broker accepts, so review it as if a prompt injection will call each one.
