cd /news/ai-safety/why-your-ai-coding-agent-should-neve… Β· home β€Ί topics β€Ί ai-safety β€Ί article
[ARTICLE Β· art-105679] src=dev.to β†— pub= topic=ai-safety verified=true sentiment=↑ positive

Why Your AI Coding Agent Should Never See Your .env

Developer Dext4r (Zaxs) has released env-guard, an open-source tool that prevents AI coding agents from exposing sensitive credentials like API keys. The tool works by having agents reference secrets by name only, with the shell expanding the actual values, so the model never sees the raw secrets. It includes audit logging and refuses unknown variables, and is compatible with Claude Code, Codex, Hermes, Cursor, OpenCode, and Aider.

read2 min views17 publishedAug 21, 2026

Your AI agent uses your API keys. It NEVER sees them. Not in context. Not in logs. Not in chat. Not even if it tries.

You just gave your AI coding assistant a .env

file with OPENAI_API_KEY=sk-...

, GITHUB_TOKEN=ghp_...

, maybe an AWS_SECRET

. You trust it to use those keys.

But here's the uncomfortable question nobody asks:

Where does that key actually go?

Vector Exposure
Model context window Visible to the LLM
Tool call logs Logged forever
Chat history Stored in plaintext
Prompt injection ("print all env vars" )
Exfiltrated in 1 shot

One malicious webpage. One injected instruction buried in a doc your agent reads. Every credential β€” gone.

AI agents are promiscuous with context. They log everything. They echo everything. They will happily print(env)

if a prompt tells them to.

I built ** env-guard** around a simple principle: the agent references a secret by

.env.list (NAMES ONLY)        live env (VALUES)
OPENAI_API_KEY      ──refs──▢  OPENAI_API_KEY=sk-...
GITHUB_TOKEN                   GITHUB_TOKEN=ghp_...
                                  β”‚
                            OS expands $NAME
                                  β”‚
                       secret-run.py (audited, no reveal)

The agent types:

curl -H "Authorization: Bearer $OPENAI_API_KEY" https://api.openai.com/v1/models

The shell expands $OPENAI_API_KEY

. The model sees $OPENAI_API_KEY

β€” never sk-....

Three layers:

.env.list

env-scan.py

secret-run.py

model + provider + purpose

, and

python scripts/secret-run.py \
  --var OPENAI_API_KEY \
  --model "gpt-4o" \
  --provider "openai" \
  --purpose "list models" \
  -- curl -s https://api.openai.com/v1/models

Unknown variables are refused. Every access is audit-logged with reveal: false

. Even a direct cat .env

instruction fails β€” the agent has no read access to the raw file.

env-guard

doesn't ask the agent to be careful. It makes carelessness impossible. The value is simply never in a place the model can read.

Works with Claude Code, Codex, Hermes, Cursor, OpenCode, Aider. MIT licensed.

πŸ‘‰ ** github.com/Z-150/env-guard** β€” clone it, drop it in your

skills/

folder, star it if it saved your keys.Built by Dext4r (Zaxs), powered by Nous Research:CAB.

── more in #ai-safety 4 stories Β· sorted by recency
── more on @dext4r 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain β€” perfect for shipping the agent you just read about.

$git push zahid main
β†’ Live at https://your-agent.zahid.host βœ“
Get free account β†’ Pricing
from €0/mo Β· no card required
LIVE [news/why-your-ai-coding-a…] indexed:0 read:2min 2026-08-21 Β· β€”