Safeguard
Security Guides•

What files should an AI coding agent never be able to read?

Keep AI coding agents away from credential files, private keys, production configs, and data exports. A practical exclusion list and how to enforce it.

Safeguard Security Team
7 min read

An AI coding agent should never be able to read credential files, private keys, cloud config directories, production environment files, browser profiles, and exports of customer data. Enforce this with isolation and file permissions, not only with a rule telling the model to stay away.

Why the question matters

Everything an agent reads can end up in a prompt, and prompts leave the machine for a model endpoint. OWASP lists Sensitive Information Disclosure as LLM02 in its 2025 Top 10 for LLM applications. A file the agent has no access to cannot leak, whatever the model does or whatever a poisoned instruction says.

The exclusion list

CategoryExamplesWhy
Credential filesenvironment files with tokens, package registry config, cloud CLI config foldersDirect account access
Key materialSSH private keys, signing keys, certificates with private partsIdentity theft, signing abuse
Production configdeploy manifests with live values, database connection settingsLateral movement
Personal datacustomer exports, support transcripts, test dumps copied from productionPrivacy duties, breach scope
Other projectssibling repositories, shared drivesScope creep
Browser and chat dataprofiles, cookie stores, message archivesSession theft

Adjust the list for your stack, but keep it short enough that people remember it.

Four ways to enforce it

  1. Mount less. In a container, mount only the project. Files that are not mounted do not exist for the agent.
  2. Use a separate account. A dedicated OS user cannot read another user's home directory by default.
  3. Keep secrets out of the tree. Load secrets from a manager at run time instead of storing them in files beside the code. For local development, use short lived tokens.
  4. Use tool level ignore rules as a second layer. Many tools can be told to skip certain paths. Treat this as a convenience, not a guarantee, since a shell command can still read what an ignore list hides.

Be honest about which of these your tools support, and test them.

A quick test

In a throwaway project, create a file named like a credentials file with a harmless dummy value. Ask the agent to summarize the repository, then to debug a config problem. Check whether it opens the dummy file and whether the content appears in any log you can see. Repeat with the ignore rules on. The results show how much to trust each layer.

Handling the accident

Assume that someday a real secret will be read. Prepare for it:

  • Know how to rotate each credential class quickly.
  • Prefer short lifetimes so rotation is mostly automatic.
  • Keep an inventory of where each credential lives.
  • Ask your tool vendor how long prompts are retained and who can access them, and keep their answer on record.

Rotation speed turns an incident into a chore.

What about code itself

Source code is often confidential too. Decide whether the repository is allowed to go to the model endpoint at all. Many teams classify repositories into tiers, such as public, internal, and restricted, and allow agents only on the first two at the start. Our post on AI coding assistant data leakage paths maps where the data can travel.

Safeguard can help at the dependency and pipeline end of this: SBOM and dependency scanning, reachability analysis, policies and gates on pull requests, and agent identity. You can try a free scan at gold.safeguard.sh/scan.

A worked example: auditing one repository

A team audits a typical service repository before enabling an agent. They list what is reachable from the working directory and from the user's home, then mark each item.

Item foundWhereAction
Environment file with a database passwordProject rootMove to a secret manager, delete the file, rotate the password
Cloud configuration folderHome directoryNot mounted in the sandbox
SSH private keyHome directoryNot mounted, agent uses a deploy token instead
Sample customer export used for debuggingData folderReplace with synthetic data, remove from the tree
Registry token in a package config fileHome directoryUse a short lived token injected per session
Sibling repositoriesParent directoryNot mounted
Test fixtures with fake dataTest folderKeep, nothing sensitive

Of seven items, five are removed from the agent's view entirely, one is replaced, and one stays. The team did not need a sophisticated product. They needed to look at what was lying around and decide.

Why local habits matter

Secrets accumulate in places that were meant to be temporary: a shell history with a pasted token, a notes file with a connection string, an exported report left in a downloads folder. A sandbox that mounts only the project avoids most of it, but the project itself should be clean too.

  1. Search the repository history for files that look like credentials, using whatever tooling your team already has, and rotate anything you find.
  2. Add the usual credential file names to your ignore list so they do not get committed again.
  3. Store local development secrets in a manager and load them at run time.
  4. Prefer tokens that expire in hours.

Handling the data the agent legitimately needs

Some tasks need realistic data. Give the agent a masked or synthetic copy. Keep the mapping to the real data outside the sandbox. If a bug only reproduces with real data, have a person run that step and give the agent the sanitized result.

Classifying repositories

Not every repository needs the same treatment.

TierExampleAgent policy
PublicOpen source librariesAllowed with standard controls
InternalTypical servicesAllowed in a sandbox with scoped tokens
RestrictedPayment, health, or key handling codeNot allowed until a specific review is done

Write the tiers down and assign each repository an owner who confirms its tier.

Measuring success

Count how many agent sessions started in a sandbox with no mounted credentials, how many credential files were removed from repositories this quarter, and the median age of tokens agents use. These numbers show whether the habit is sticking.

Try it yourself

Click through it at your own pace, or open it full screen.

Click through and notice what a dependency inventory shows about a project.

Quick check

Is an ignore file enough?

No. It is a hint to the tool, and a command line can bypass it. Use isolation as the main control.

Should test data come from production?

Avoid it. Synthetic or masked data keeps the agent, and your logs, out of privacy scope.

What if the agent does read a real secret?

Rotate it immediately, review provider logs for use since the exposure, and check where the session's prompts are retained.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.