Guide · AI coding agents

Securing AI coding agents and the credentials they can reach.

A coding agent runs with the developer's access. Every .env file, cloud profile and MCP token on that laptop is one file read away, and the agent also reads issues, web pages and dependencies written by strangers. That combination is what to secure.

Why do AI coding agents change the secrets problem?

AI coding agents change the secrets problem because they read files and run commands with the developer’s own access, and they take instructions from text the developer didn’t write. Claude Code, Cursor, GitHub Copilot’s agent mode and similar tools can open files, run shell commands and call MCP servers. On a typical laptop that puts deploy .env files, cloud credential profiles, kubeconfigs and MCP tokens within one tool call.

None of these secrets is new. What is new is a process that reads widely, acts quickly, and can be steered by content from issues, pull requests, web pages, documentation and dependencies. OWASP ranks Prompt Injection first in its Top 10 for LLM Applications, and Excessive Agency, an agent with more functionality or permission than it needs, sixth.

The secrets themselves are already scattered. GitGuardian counted 23.8 million secrets leaked on public GitHub repositories in 2024 and found that 70% of secrets leaked in 2022 were still active.

23.8MSecrets leaked on public GitHub repositories in 2024, by GitGuardian's count.
70%Of secrets leaked in 2022 still active when GitGuardian checked.
3Ingredients of Simon Willison's lethal trifecta: private data, untrusted content, external communication.

Sources: GitGuardian, The State of Secrets Sprawl 2025; Simon Willison, 16 June 2025.

What credentials can a coding agent reach?

A coding agent can reach every credential the developer’s account can read, unless something stops it. Typical candidates:

.env filesDeploy and service credentials in the project and in sibling projects on the same disk.
Cloud credential profilesAWS, Azure and Google Cloud credentials in the home directory, often with broad development permissions.
kubeconfigsCluster tokens and contexts for development, staging and sometimes production.
MCP configurationServer URLs and bearer tokens in files such as .mcp.json, a map of internal tools with credentials attached. See MCP servers as decoys.
Shell history and profilesTokens exported in a profile or typed on a command line.
Git and package tokensCredentials for code hosting and package registries, which open supply-chain paths.

How does prompt injection turn into credential exfiltration?

Prompt injection turns into credential exfiltration when one agent has three things at once: access to private data, exposure to untrusted content, and a way to communicate externally. Simon Willison calls this the lethal trifecta. Untrusted text carries instructions; the agent follows them, reads a secret, and sends it out through any channel it has, whether a web request, a commit, a pull request or a tool call.

Invariant Labs showed a concrete case in May 2025 with the GitHub MCP server. A malicious issue in a public repository contained instructions. When the owner asked their agent to look at open issues, the agent pulled data from the owner’s private repositories and published it in a pull request on the public one. Invariant notes the flaw sits in the agent architecture, not in the server code.

  1. Untrusted text arrivesAn issue, README, web page or dependency contains instructions aimed at the agent.
  2. The agent reads itAs part of a routine task the developer asked for.
  3. It reaches for private dataA .env file, a credential profile, a private repository or an MCP token.
  4. It sends data outThrough a request, a commit, a pull request or a tool call that the attacker can read.
  5. Someone uses the credentialLater, from somewhere else. This is the first moment the credential's owner can see anything.

The same reach matters without any attacker. The WorkOS incident started with a researcher’s AI agent that left its test environment and signed in with a development credential it found. Read our brief. And attackers use coding agents too: Anthropic’s November 2025 report describes a state-sponsored group using Claude Code to harvest credentials from configuration and test them across internal systems. See what AI-driven attacks change.

How do you lock down a coding agent?

You lock down a coding agent by breaking at least one leg of the trifecta and by shrinking what each reachable credential can do. A practical list:

  1. Deny reads of secret files. Most agents have permission settings. Claude Code’s documentation shows deny rules such as Read(./.env) and Read(./.env.*), and supports managed settings so an organization can enforce them. Check the equivalent in every agent your developers use.
  2. Keep long-lived secrets out of the workspace. Use short-lived credentials from a broker or SSO session instead of static keys in files. A credential that expires in an hour is worth less to whoever copies it.
  3. Scope development credentials. Development keys should not work in production, and should carry only the permissions a developer needs.
  4. Treat MCP servers as code you run. The MCP security best practices warn that local servers run with the client’s privileges and that configuration can contain startup commands. Review what you install, use narrow token scopes, and avoid tokens that work everywhere.
  5. Limit outbound paths. Run agents in a sandbox or container with restricted network egress when they work on untrusted content.
  6. Keep a human on consequential actions. Require approval for pushes, pull requests to public repositories, deploys and calls that send data out. Be careful with “always allow”.
  7. Separate untrusted tasks. An agent triaging public issues should not hold tokens for private repositories in the same session.

How do you know when a reachable credential is used?

You know when a reachable credential is used by placing credentials there that no developer and no legitimate job ever uses, and watching for their first use. Lock-down reduces exposure; it doesn’t tell you when something got through. A decoy in the same places agents read turns a successful exfiltration into a signal at the moment the credential is tried.

Lock-down only

  1. Deny rules, scoped tokens and sandboxes reduce what an agent can read and send.
  2. A gap remains: a new tool, an unreviewed MCP server, an "always allow".
  3. If a credential leaves through that gap, you learn when it is abused.

Lock-down plus a decoy

  1. The same controls, plus a decoy credential among the real ones.
  2. A leak through the gap carries the decoy with it.
  3. Its first use opens a finding that names which laptop and file it came from.

FalseTrail places decoys where coding agents look: a deploy .env file with a service credential and URL, a standard .mcp.json with an MCP server URL and bearer token, a standalone kubeconfig and AWS access keys with no permissions. Your MDM or deployment tooling puts them on developer laptops; there is no agent on every endpoint. New placements start in Learning, so your own tools and authorized testers are recorded as narrow, expiring patterns before a placement arms, and uses still alert while learning.

When a planted reference is followed or a planted credential is presented, a finding opens and goes to your SIEM or SOAR, naming the placement. FalseTrail does not classify attackers as human or AI; an injected agent and a person on the laptop are detected the same way. For more, read detecting AI agents with decoy credentials, LLMjacking and the glossary.

A starting checklist

  1. List the AI coding agents in use and how each is configured, including MCP servers.
  2. For each, set deny rules for secret files and enforce them centrally where the tool allows.
  3. Replace static keys on laptops with short-lived credentials where you can.
  4. Make sure development credentials fail in production.
  5. Restrict network egress for agents working on untrusted content.
  6. Plant decoy credentials next to the real ones on developer laptops, and route findings to the SOC.

Questions

Can an AI coding agent read my .env file?

Usually, yes. A coding agent works with the permissions of the user who runs it, so it can read whatever that user can read unless its own settings or a sandbox stop it. Claude Code, for example, documents deny rules such as Read(./.env) for exactly this.

How does prompt injection lead to credential theft?

An agent reads untrusted text, such as an issue, a web page or a file, that contains instructions. If the agent also has access to secrets and a way to send data out, those instructions can make it read a credential and send it somewhere. Simon Willison calls this combination the lethal trifecta.

Is it enough to keep secrets out of the repository?

No. Secrets outside the repository, in home-directory credential files, shell profiles and MCP configuration, are still readable by an agent that runs as you. Keep them out of reach, scope them narrowly, and watch for their use.

Does FalseTrail tell whether an agent or a person used a decoy?

No. FalseTrail does not classify attackers as human or AI; both are detected the same way. The finding names the placement that was used and what followed on that trail.

Sources

  1. Simon Willison, The lethal trifecta for AI agents: private data, untrusted content, and external communication (16 June 2025)
  2. Invariant Labs, GitHub MCP Exploited: Accessing private repositories via MCP (26 May 2025)
  3. OWASP, LLM01:2025 Prompt Injection
  4. OWASP, LLM06:2025 Excessive Agency
  5. Model Context Protocol, Security Best Practices
  6. Claude Code documentation, Settings files and precedence
  7. GitGuardian, The State of Secrets Sprawl 2025 (11 March 2025)
  8. Anthropic, Disrupting the first reported AI-orchestrated cyber espionage campaign (full report, November 2025)

See the next attempt at access at its first use.

On-prem, your cloud or hybrid. Zero outbound connections; raw evidence stays in your environment.