diffox
Blog

AI agent identity: rules for giving agents tokens and secrets

Why AI agent identity should be separate from yours, and how to give agents GitHub tokens and secrets. We read OWASP, identity platforms and five tools’ docs.

ShareXLinkedIn

Summary. AI agent identity is an AI agent’s own identity, separate from your account, and the tokens that represent it. On 5 November 2026 we read OWASP’s list of risks for agents, an IETF draft, the agent identity documentation of Microsoft, Okta, AWS and Google, GitHub’s token documentation, and the settings five coding agents have for secrets.

  • If the agent can read a secret, prompt injection can send it out. According to OWASP’s 2026 list, most high-impact prompt injection incidents on record became severe because the model could act with the user’s privileges.
  • The rules are not new. Short-lived, narrowly scoped tokens, one identity per agent, secrets the agent never sees and a record of every action are familiar from service accounts; OWASP’s lists, the IETF draft and the identity platforms reach the same rules for agents.
  • The token from your own GitHub session gives the agent your permissions in all your repositories. A classic personal access token, too, opens every repository you can access. A GitHub App token opens only the repositories the app is installed on, and expires after 1 hour.
  • The agent’s commands can see the secrets in your shell. The documentation of Claude Code, Codex and Copilot describes this as the default. The way to use a secret without showing it to the agent is a proxy that adds the real value to the outgoing request.

What is AI agent identity, and why should an agent have its own?

3rdIdentity & Privilege Abuse’s rank on OWASP’s list for agents (December 2025)
1 hourlifetime of a GitHub App token; a personal access token may never expire
136days an admin key leaked to a public repository stayed valid (LiteLLM)
5 minlifetime of the OIDC token Cursor gives its cloud agent

In the sandbox post we covered what limits an agent’s commands, in the prompt injection post how a repository can steer an agent, and in the cloud agents post whose permissions an agent in the cloud works with. This post looks at the question all three share: which identity, which token and which secret should an agent work with?

AI agent identity is an agent’s own identity, separate from your account: an app, a service account or a workload identity, and the tokens and keys that represent it. OWASP is a nonprofit foundation that works on software security (we covered its lists in a separate post). Its Agentic Top 10, written for agents, defines identity in two parts: the agent’s assigned identity, and every credential that represents it, meaning API keys, OAuth tokens and sessions opened on a user’s behalf.

Number 3 on the list is Identity & Privilege Abuse. According to OWASP, the work of an agent without a governed identity of its own cannot be fully attributed to anyone, and truly enforcing the principle of least privilege becomes impossible. Microsoft’s Entra Agent ID documentation gives similar reasons for agent identities: to tell what agents do apart from what employees and services do, to give an agent just enough access for its job, and to keep it away from the most critical roles.

With coding agents, the default is often the opposite: the agent works as you. According to Claude Code’s documentation, the commands the agent runs inherit your environment variables, secrets included. According to GitHub, Copilot’s local sandbox is off by default, and while it is off, commands can use your credentials without restriction. In the cloud, the tools differ: the commits and pull requests of Claude Code’s scheduled tasks carry your GitHub user, while Copilot’s and Cursor’s cloud agents commit under their own names. When the agent works as you, what it does shows up in the logs as your own work.

What can an agent do with the token it holds?

Prompt injection means hiding instructions in text a model reads, to change how it behaves. The text alone can do nothing; the permissions the agent holds decide how much harm it does. OWASP’s 2026 list says so plainly: most high-impact prompt injection incidents on record became severe because the fooled model could use its tools and permissions to act for the attacker, at the user’s privilege level.

OWASP’s example describes a coding agent directly: the attacker leaves text in a low-privilege channel the user trusts, such as a community pull request, and waits for the developer’s assistant to read it with the user’s elevated privileges. The privileged action is taken by the agent, not the attacker. In the Invariant Labs example we described in the MCP security post, too, an issue in a public repository got the agent to leak information from the user’s private repositories.

In the same place, OWASP passes on a check Simon Willison calls the “lethal trifecta”: if an agent can access private data, read untrusted content and communicate externally at the same time, the conditions for a serious attack are in place; removing any one of the three breaks them. A secret, meaning an API key, a token or a password, sits on the first leg of that trifecta: any secret the agent can read can be sent out through prompt injection. That is exactly why Claude Code’s documentation says its setting that strips secrets from commands’ environments “reduces what a prompt injection attack can read”.

Whose token it is also decides the damage. LiteLLM had built an experimental platform for cloud agents that open pull requests. According to its root cause analysis of 23 October 2026, the platform connected to GitHub not with a token narrowed to repositories and permissions, but with the GitHub CLI OAuth token of one of the organization’s owners. The platform’s admin key had been committed to a public repository by mistake on 27 May; the file was deleted about 3 hours later, but the key was never revoked.

On 10 October, the attacker used this key to read the agents’ settings through the platform’s API and took the token; according to LiteLLM, from then on the attacker had owner privileges in the organization. On 21 October, the attacker used the same token to override branch protection and change the release workflow, and the malicious version 1.107.0 was published to PyPI. We covered the settings that hold back a newly released version at install time in the slopsquatting post. In its first statement, LiteLLM thought the token had been taken from an internal system’s logs; the root cause analysis corrected that.

Which rules apply when you give an agent a token?

The rules for an agent are not new; they are familiar from service accounts and CI. OWASP also keeps a separate list for the identities given to software, such as service accounts, API keys and bots: the Non-Human Identities Top 10 (NHI). That list, OWASP’s list for agents and a new draft from the IETF, which writes internet standards, all reach the same rules:

Rules for giving an agent a token. OWASP’s two lists and the IETF draft reach the same rules. Short-lived: A token that ends with the job; no key that never expires. Narrowly scoped: Only the repository and permissions the job needs. One identity per agent: Neither your account nor a shared service account. The secret outside the agent: The agent sees a placeholder; a proxy or broker fills it in. A record of every action: Which agent, on whose behalf, touched what?
Source: OWASP Agentic Top 10 (ASI03), OWASP Non-Human Identities Top 10 and the IETF draft draft-ietf-wimse-aims, 5 November 2026.

A short lifetime means a leaked token stops working on its own. The first recommendation under OWASP’s Identity & Privilege Abuse entry is to issue short-lived, narrowly scoped tokens for each task. The IETF draft also asks for an agent’s credentials to be short-lived and to carry an explicit expiry time, and calls static API keys an anti-pattern for agent identity. According to the NHI list, a long-lived secret that leaks gives the attacker access with no time limit. And deleting the file does not revoke the key: Claude Code’s GitHub Actions documentation reminds you that the key in a secret you delete from the repository stays valid, and LiteLLM’s key stayed valid for 136 days after it was deleted. By its own measurement, GitGuardian, which sells a secret scanning tool, found that 64% of the valid secrets it detected in public repositories in 2022 were still valid 4 years later.

A narrow scope means giving the agent only the repository and the permissions its job needs. OWASP’s Excessive Agency entry takes its example straight from a code repository: a tool that reads a user’s repository should get its permission from the user through OAuth, with the narrowest scope it needs. The IETF draft, too, says an agent should request only the minimum scopes a task needs.

One identity per agent separates what the agent does from what you do, and what one agent does from what another does. The NHI list asks for a separate identity for each application or service, because a shared identity taken over in one place opens a door to every place that uses it. This does not mean the agent works independently of you. GitHub’s documentation separates two paths: if you want the app’s work to show under the app’s name, the app works with its own installation token; if you want it to show under a user’s name, it works with a token it got on that user’s behalf. In the second case, too, the agent holds not your own token but a token granted to the app on your behalf; according to the IETF draft, OAuth means the agent never needs access to your credentials when it acts on your behalf.

Keeping the secret outside the agent means the agent never sees it. OWASP recommends holding credentials and the ability to change state in application code, not in the model. With coding agents, the equivalent is a proxy: the agent sees a placeholder instead of the secret, and the real value is added as the request leaves the agent’s machine. How each tool does it is below.

A record means something once identities are separate. The IETF draft asks for a durable, tamper-evident log of every authorization decision; at a minimum, the log should say which agent acted, on whose behalf, what it accessed and what the decision was. If the agent works with your token, the log shows only you. LiteLLM could trace the attacker’s steps through the token hashes GitHub’s audit log keeps for every action, but the commit that changed the release workflow had been made in the organization owner’s name. We covered how to record what an agent does on your own side in the OpenTelemetry post.

Which GitHub token should you give an agent?

A coding agent’s work usually ends on GitHub: it clones the repository, pushes to a branch and opens a pull request. What the token it holds for this can do depends a lot on its type: on whose behalf it acts, what it can reach and how long it lives.

The tokens an agent can hold on GitHub: on whose behalf each acts, what it reaches and how long it lives
TokenOn whose behalfWhat it reachesHow long it lives
gh auth login sessionYoursAccording to the documentation, at least the repo, read:org and gist scopes; repo means read and write access to all your repositoriesRevoked by GitHub if unused for 1 year
Classic personal access tokenYoursEvery repository you can accessAn expiry date is optional
Fine-grained personal access tokenYoursA single account or organization; the repositories and permissions you chooseYou choose; it can be set never to expire unless an organization policy blocks it
GitHub App installation tokenThe app’sThe repositories the app is installed on; can be narrowed to single repositories and permissions when requested1 hour
GITHUB_TOKEN in ActionsThe GitHub App installed on the repositoryThe repository the workflow is inUntil the job finishes; at most 6 hours on GitHub’s runners
Cloud token obtained with OIDCThe workflow’sThe role the cloud side’s trust definition allowsA single job; then it expires on its own

Source: GitHub’s and GitHub CLI’s documentation, 5 November 2026.

GitHub’s documentation defines the personal access token for work you do on your own behalf, and recommends a GitHub App for work on an organization’s behalf or for a long-lived integration. A personal access token can do everything its owner can, as far as its scopes allow, and a classic one opens every repository you can access. Giving an agent the token from your own session means giving it your permissions in all your repositories.

For an agent that runs on your own machine, the personal access token GitHub recommends is the fine-grained one: a token with only that repository and the permissions it needs selected, and an expiry date. If the agent will run continuously for a team or an organization, set up a GitHub App: its token expires after 1 hour, can be narrowed to a single repository and a few permissions when requested, and its work shows under the app’s name.

In CI, the way to store no secrets is OpenID Connect (OIDC): according to GitHub, the workflow gets a token from the cloud provider that is valid only for that job and expires on its own, so you don’t need to store cloud keys as GitHub secrets. The same path exists for the agent’s model key: Claude Code’s GitHub Action can exchange the workflow’s OIDC token for Claude API access through a service account. Codex’s documentation also says not to set the API key as a job-level environment variable in jobs that run the repository’s code; build scripts, tests and dependencies’ install hooks can read it.

If a token leaks anyway, GitHub has two safeguards. Push protection stops a push that contains a secret before it reaches the repository, and for personal accounts it is on by default for public repositories. According to GitHub, a valid GitHub token pushed to a public repository is also revoked automatically. Both catch a secret pushed to GitHub; neither catches a token that leaks into a log or another service.

What do identity platforms offer for agents?

Identity providers define the agent as a separate kind of identity, and OWASP’s list for agents recommends evaluating these platforms. What follows is what the vendors’ own documentation says, not a ranking:

What four identity platforms’ documentation says about agent identity: what each gives the agent, where it keeps the secret and what else it says
PlatformWhat it gives the agentWhere it keeps the secretAlso in the documentation
Microsoft Entra Agent IDAn agent identity in Entra for each agent; can be created in bulk from a template (blueprint). On a user’s behalf, with the rights the user grantedAgent identities don’t use people’s sign-in methods; they get their tokens from EntraAll of the agent’s authentication and activity is logged; when an agent is removed, no orphaned credentials or permissions are left behind
Okta for AI AgentsThe agent is registered in Okta, authenticates with a public key and connects to resources through standard token exchange flowsAuth0’s Token Vault stores the tokens of the services a user connected; the application gets them with a token exchangeAgent events in the System Log; a deactivated agent can’t connect to any resource
Amazon Bedrock AgentCore IdentityA unique identity and ARN for each agent, in a central directoryToken vault: OAuth tokens and API keys; only an authorized agent that proves its identity can get themEvery operation is logged with its context; no need to embed secrets in the agent’s code or configuration files
Google Cloud Agent IdentityAn identity based on the SPIFFE standard, tied to the agent’s lifecycle, and a 24-hour X.509 certificateFor work on a user’s behalf, narrowly scoped OAuth credentials brokered by Agent IdentityDeleting the agent doesn’t delete its IAM permissions; you have to remove them by hand

Source: the vendors’ own documentation, 5 November 2026. SPIFFE is a widely used open standard for giving workloads an identity. These platforms connect the agents an organization runs to its own identity system; the coding agents’ own settings are in the next section.

Most of the documentation shares the same ideas: a separate identity for each agent, the secret kept in a vault or in the identity provider rather than in the agent’s code, a short-lived token the agent gets when it needs one, and a log of every action. That is what a credential broker is: a service that holds the long-lived secret itself and gives the agent a short-lived, narrow token on request. Its protocol is a standard too: the IETF’s OAuth 2.0 Token Exchange (RFC 8693) defines how such a service, which trades one token for another, works, including work done on someone else’s behalf.

Work on the standards is still going on. The OpenID Foundation, a body for identity standards, wrote in a whitepaper published on 7 October 2025 that enterprises need to begin treating agents as “first-class citizens” in their identity infrastructure. The AIMS draft of WIMSE, the IETF’s working group on workload identity, dated 2 November 2026, proposes no new protocol: it describes how existing standards apply to agents, and requires every agent to have a unique identity. An Internet-Draft is not yet a standard. NIST, the US standards institute, also published a concept paper on agent identity and authorization on 5 February 2026 and asked for comments.

Can a coding agent see your secrets?

How close a secret sits to the agent decides whether the agent can read it:

How close is the secret to the agent?. In the first two, the agent can read the secret; in the last two, it can’t see it. GITHUB_TOKEN · AWS_* In the environment: Every command the agent runs can read it. .env · ~/.aws In a file: A read rule stops the agent’s tool, not every script. placeholder In a proxy: The agent sees a fake value; the request gets the real one. token exchange In a broker: The agent gets a short-lived, narrow token, not the secret.
Compiled from the documentation in this post, 5 November 2026. Examples of a proxy and a broker are in the table below and in the previous section.

On 5 November 2026 we read the documentation of five coding tools with three questions: do the commands the agent runs see the environment variables in your shell, how do you keep the agent out of a file such as .env, and is there a way to use a secret without showing it to the agent?

Secrets in five coding tools: the environment variables commands see, how to keep the agent out of a file, and using a secret without showing it to the agent
ToolEnvironment variables commands seeBlocking a file such as .envUsing a secret without showing it to the agent
Claude CodeEverything in Claude Code’s environment, secrets included. CLAUDE_CODE_SUBPROCESS_ENV_SCRUB=1 removes most of them but leaves GitHub tokensA Read(./.env) rule stops the file tools and commands such as cat, not a script that opens the file itself; the sandbox stops every process. There is no built-in list of secretsmask in the sandbox: the command sees a per-session placeholder, and the proxy adds the real value for hosts you allow. In the cloud, network secrets and a GitHub proxy for git
CodexAll of them by default, including those whose names contain KEY, SECRET or TOKEN. ignore_default_excludes = false removes thoseA "**/*.env" = "deny" rule in the permission profile; commands in the sandbox can’t read the fileNetwork secrets in Codex Cloud: the program gets a placeholder, and the proxy adds the real value for allowed destinations
GitHub CopilotThe local sandbox is off by default; while it is off, commands can use your credentials without restrictionYou can deny the path in the local sandbox’s Filesystem settingIn the local sandbox, gh gets a placeholder GH_TOKEN, and the real one goes only to github.com addresses. In the cloud agent, secrets are environment variables, and their values are masked in the logs
CursorNot stated in the documentation.cursorignore stops the agent’s file tools, not its terminal and MCP tools. By default, read access covers the whole systemRuntime Secret in the cloud agent: the value stays an environment variable and is removed from the transcript and commits
AntigravityNot stated in the documentationThe terminal sandbox blocks ~/.ssh and .env; on by default in the app, turned on by auto mode in the CLIIn the remote agent, the OAuth tokens of the services you connect are stored encrypted and added at request time

Source: the tools’ documentation, 5 November 2026. “Not stated in the documentation”: in the pages we read that day, we found no sentence that describes this. In OpenCode, reading is allowed, but .env files ask for approval by default; most other permissions default to “allow”.

In the three tools whose documentation says so plainly, Claude Code, Codex and Copilot, the commands the agent runs see the secrets in your environment by default. Codex has a ready-made filter that drops variables whose names contain KEY, SECRET or TOKEN, but it is off by default; its documentation recommends choosing the variables explicitly so that unneeded secrets don’t reach commands. That is why, in every tool, it helps to start the agent in a shell without the tokens it doesn’t need.

File rules stop the agent’s own tools, not every program. According to Claude Code’s documentation, a Read(./.env) rule doesn’t stop a Python or Node script that opens the file itself; Cursor, too, writes that .cursorignore doesn’t apply to the terminal and MCP tools and doesn’t guarantee complete protection. What stops every process is a sandbox at the operating system level: the deny rule in Codex’s permission profile, Antigravity’s sandbox and the credentials setting in Claude Code’s sandbox work at that level. Claude Code’s documentation also reminds you that there is no built-in list of secrets: only the files and variables you list are protected.

The way to never show the agent a secret is the same in every tool: the agent sees a placeholder, and a proxy outside the agent adds the real value as the request goes to an allowed address. That is what a credential proxy is. It exists in the local sandboxes of Claude Code and Copilot CLI, in Codex Cloud and in Claude Code’s cloud sessions; in Claude Code’s cloud environment, git uses a narrowly scoped credential instead of your real GitHub token, and the proxy swaps it for the real one outside.

Some cloud agents have an identity of their own. Copilot’s cloud agent commits in its own name, adds the person who started the work as a co-author and can push to only one branch; if the repository already requires an approval, a pull request it opens under its own identity needs one more. Cursor’s cloud agent commits as “Cursor Agent”, and instead of long-lived keys it can reach cloud roles with 5-minute OIDC tokens bound to the agent and its owner. Claude Code’s scheduled tasks, on the other hand, run as your user. The cloud agents are covered in detail in the cloud agents post.

A code review service also reaches the repository the way an agent does, and the same rules apply to it. Our AI code review tool, diffox, reaches the repositories it reviews as a GitHub App, not with a person’s token. It exchanges a JWT, signed with its own key and valid for a few minutes, for a 1-hour token from GitHub that opens only the repositories you gave the app access to, and it keeps that token in memory only. When it clones the repository, the token travels in a request header, not in the address, and is never written to disk. The process that does the review starts in an environment built from scratch: apart from the model keys that review uses, it sees no secret on the server, and not the GitHub token either. The review is left on the pull request as comments, and diffox never blocks the merge.

Frequently asked questions

What is AI agent identity?

It is an AI agent’s own identity, separate from your account: an app, a service account or a workload identity, and the tokens and keys that represent it. According to Identity & Privilege Abuse, number 3 on OWASP’s list of risks for agents, the work of an agent without an identity of its own cannot be fully attributed to anyone, and enforcing the principle of least privilege becomes impossible. Microsoft Entra Agent ID, Okta for AI Agents, Amazon Bedrock AgentCore Identity and Google Cloud Agent Identity are products built to provide that identity, and the IETF’s WIMSE working group is working on a draft that requires every agent to have a unique identity.

Should I give an agent my own GitHub token?

Don’t give it the token from your own session. According to GitHub, a personal access token can do everything its owner can, as far as its scopes allow; a classic personal access token opens every repository you can access, and the repo scope that gh asks for grants read and write access to all your repositories. For an agent on your own machine, create a fine-grained token with only that repository and the permissions it needs selected, and an expiry date. If the agent will work for a team or an organization, GitHub recommends a GitHub App: its token expires after 1 hour and can be narrowed to a single repository. In CI, use OIDC for cloud keys.

What is a credential broker?

It is a service that holds the long-lived secret itself and gives the agent a short-lived, narrowly scoped token on request. The agent never sees the real secret, and even if the token it holds leaks, it soon stops working. Auth0’s Token Vault and the token vault of Amazon Bedrock AgentCore Identity do this job; on the protocol side, it is the IETF’s OAuth 2.0 Token Exchange standard (RFC 8693). A credential proxy is a close idea: the agent sees a placeholder instead of the secret, and the proxy adds the real value to the outgoing request. Claude Code’s sandbox, Copilot CLI’s local sandbox and Codex Cloud’s network secrets work this way.

Can a coding agent read the .env file?

In most tools it can, unless you write a rule. In Claude Code, a Read(./.env) rule stops the file tools and commands such as cat, but not a script that opens the file itself; to stop every process, you need to turn on the sandbox and add the file to the credentials setting. In Cursor, .cursorignore doesn’t cover the terminal and MCP tools. In Codex, you can write "**/*.env" = "deny" in the permission profile. Antigravity’s terminal sandbox blocks .env and is on by default in the app; OpenCode also asks for approval before reading .env. To keep a file away from every program, a file tool’s rule isn’t enough: you need a sandbox at the operating system level.

What is a short-lived token?

It is a token that expires on its own, usually issued for a single job or a few minutes. If it leaks, it gives an attacker access only for the time it has left. A GitHub App installation token expires after 1 hour, the GITHUB_TOKEN in Actions when the job finishes, and a cloud token obtained with OIDC is valid for a single job; the OIDC token Cursor gives its cloud agent lives for 5 minutes. The IETF’s draft on agent identity asks for an agent’s credentials to be short-lived and to carry an explicit expiry time, and calls static API keys an anti-pattern for agent identity.

How does diffox access my repository?

As a GitHub App. diffox gets an installation token from GitHub that opens only the repositories you gave the app access to and expires after 1 hour, and keeps it in memory only. When it clones the repository, the token travels in a request header, not in the address, and is never written to disk. The process that does the review doesn’t see the GitHub token; it works only with the model keys that review uses. Findings are posted on the pull request as comments; diffox never blocks the merge.