// How-to · Let agents run safely
Keep agents from reading .env files and committing secrets
Any file an agent can read may end up in the model context, logs or even commits. Handle it on three fronts: expose less, detect early, rotate fast.
verified 2026-10-102 official sources
Scenario: Let agents run safely →
Symptoms
- API keys show up in commits or agent logs
- A provider notifies you of a leaked key
Common causes
- Secrets live in plain text in the project’s
.envand the agent can read it - There is no pre-commit scanning
How to fix
- Use the client’s deny rules to block reading
.env, key files and credential directories - Keep secrets in a secrets manager (e.g. Vault, Infisical) and inject them at run time instead of storing them in the repo
- Add pre-commit scanning, e.g.
gitleaks gitorgitleaks protect(check your version’s docs), and scan again in CI - Revoke and regenerate leaked keys at the provider immediately; deleting the commit is not enough
- Scan the full history with trufflehog to make sure nothing else slipped through
Official references
Compiled from official documentation and public discussions on 2026-10-10; not yet reproduced in our own environment. Follow the official docs if they differ.