Dev.to Security ๐Ÿ” Cybersecurity ๐Ÿ‘ 0 ๐Ÿ“– 3 min read

I built a .env file my AI agent can use but never read

AI coding agents are great at calling APIs. To do that, they need API keys. And the easiest place to put a key is a .env file in the project, which the agent can read like any other file. From there the key ends up in th

AI coding agents are great at calling APIs. To do that, they need API keys. And the easiest place to put a key is a .env file in the project, which the agent can read like any other file. From there the key ends up in the agent's context, in the chat history, in logs, and sometimes in code it writes.

I wanted my agent to use my secrets without ever seeing them. So I built facedown.

How it works

Secrets live in one file in your project, .env.facedown:

# @desc token for the GitHub API
# @allow api.github.com
GITHUB_TOKEN=enc:v2:8kZ0โ€ฆ
  • Names, notes and allowed sites are plain text. The agent reads them to know what exists.
  • Values are encrypted (AES-256-GCM). The key isn't in the project: it's in your home folder, locked to your Windows account with DPAPI.
  • There's no command that prints a value. A secret only ever goes to two places: the environment of a program you run, or an outgoing web request.

The agent gets MCP tools instead of the values:

  • run_with_secrets: runs a command with the keys it names as environment variables.
  • http_request: sends a request with {{GITHUB_TOKEN}} placeholders that facedown fills in.
  • add_key: opens a small window on your screen where you type the value.

Printing a secret is fine

Your code can log a secret while debugging. The output just shows which key it was:

[debug] using token ***GITHUB_TOKEN*** | as base64: ***GITHUB_TOKEN:base64***
facedown: note: hid the value of GITHUB_TOKEN (2x) in the output.

Base64, hex and every common URL encoding are caught. A random stress test throws thousands of secrets, encodings, split chunks and pauses at the cleaner on every commit. It already found one real leak (two overlapping secrets), which is fixed.

Each key has a list of sites

A key can only be sent to the hosts on its list. A new key has none. Adding a site opens a confirmation window that only a click on Allow approves; Enter means Cancel. And the list is part of the encryption: if something edits # @allow by hand, that key stops decrypting instead of being sent to the new site.

What it doesn't do

It's a seat belt, not a vault door. An agent with a full shell that is deliberately trying to steal a secret can get around it: it runs as you, so it could scramble the value before printing it, or unlock the key file the same way facedown does. The strongest setup is an agent with only the http_request tool and no shell. Then the allowed-sites list is a real wall.

Try to break it

I think the rest holds, so there's a challenge: a script puts a random flag into a demo vault (nobody ever sees it), and you try to get it out through normal use. Rules and setup: docs/CHALLENGE.md. Reports go through GitHub's private vulnerability reporting, and finders get credited.

Get it

  • Claude Code: /plugin install facedown --marketplace necromancer124/facedown
  • Anywhere else: npx facedown help, and facedown mcp for any MCP client. It's also in the official MCP Registry as io.github.necromancer124/facedown.
  • Windows for now; Linux and macOS are planned after 1.0. Node 20+, no dependencies, MIT.

Repo: https://github.com/necromancer124/facedown

Feedback welcome, especially "this broke" or "this was annoying" u know the good stuff.

๐Ÿ“ฐ Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes โ€” full credit and traffic to the original publisher.