To do anything useful, an AI agent has to authenticate to the systems it acts on, e.g.: a source control platform, a ticketing system, a cloud account, a database, an inference API. In most deployments today, the agent authenticates the same way a script would, with a credential it holds in its own environment. This article describes the common patterns and the weaknesses each one carries.

API keys in the environment

The most common pattern. A key for each target system is placed in an environment variable or a configuration file where the agent runtime can read it. It is simple and it works with every framework. It is also the weakest option: the key is a long-lived bearer secret, readable by any process on the host, by any prompt-injected instruction that can trigger a file read, and by anyone who obtains a copy of the environment.

Personal access tokens and the developer’s own credentials

Coding agents in particular often run under the developer’s identity, using their personal access token, their cloud CLI session, or their SSH key. The agent then has everything the developer has. Any manipulation of the agent is a manipulation of the developer’s account, and the audit trail attributes the agent’s actions to the human.

OAuth tokens

Some agents obtain OAuth access tokens, either through a client-credentials grant (which makes the agent a service account) or by borrowing a user’s delegated token. OAuth is a better foundation because tokens can be scoped and expire, but in practice agent tokens are often issued with broad scopes and long lifetimes, refreshed automatically, and stored in the same environment as an API key would be. The token is still a bearer credential: possession is proof.

Cloud IAM roles and workload identity

When an agent runs inside a cloud environment, it can assume an IAM role attached to its instance, container, or service account. This removes static keys from the picture, and the credentials it obtains are short-lived. The weakness is scope and attribution: the role is usually shared by everything running on that workload, its permissions are set broadly, and the cloud cannot tell which agent, acting for which person, made a given call.

Secrets managers

Storing credentials in a vault rather than in files is an improvement in custody and rotation. But the agent still has to retrieve the secret to use it, and once retrieved, the secret is in the agent’s memory and subject to the same exposure as before. The vault protects the secret at rest; it does not change who holds it at the moment of use.

The above mechanisms all share the same weaknesses

Every pattern above has the same weakness. The agent holds a credential, and the target system accepts that credential from whoever presents it. Nothing verifies that the presenter is the agent it was issued to, on the host it was issued to, acting for an owner who is still entitled, for an action within the task’s scope. In each case the credential stands in for identity, and credentials can be copied.

What a better model looks like

Two changes address these weaknesses. First, take credentials out of the agent entirely: a broker or gateway holds them and injects them into each call after checking it, so the agent never sees a secret. Second, give the agent an identity that is bound to the platform it runs on, so that even a request from the right agent is refused if it comes from a copy running somewhere else. Later articles in this series cover both.

Next Article: What is the Model Context Protocol (MCP)?