DEV Community

Cover image for Your AI agent shouldn't see your API keys
Container
Container

Posted on

Your AI agent shouldn't see your API keys

Three incidents from the past month made me rethink where my agents keep secrets.

  • Cursor. Coding-agent traces stolen in a breach contained users' credentials. The attacker used them to reach other services.
  • Phala, a provider behind OpenRouter. The attacker could see request contents, and tokens from those requests were later misused.
  • LLM routers. A recent study tested 428 third-party routers. Nine of them swapped the model's tool calls for malicious ones.

Anthropic and OpenAI probably have some of the best security in the world. Smaller providers can be breached, and then a malicious tool call runs on your machine.

Where keys usually live

Usually keys sit where the agent can reach them. In Hermes, for example, they are stored on disk next to the token for remote server access.

The agent adds them to requests without reading them. But even strong models slip. A file holds JSON, and the model decides it's an env file. Every now and then Claude Code tells me it accidentally read a secret.

Still, agents need secrets. They already handle customer requests, work with repositories and monitor servers, and that list will only grow.

So I built den, a personal agent that runs on your own machine and that you can trust with your accounts. It handles the problem in three ways.

1. The agent never sees keys

The agent runs with limited permissions and talks to the outside world through den's daemon. Say it needs to check a Grafana dashboard. It sends a plain request, and den's proxy adds the authorization header.

The token is bound to the Grafana host, so it can't be sent anywhere else.

How den keeps API keys from the agent

2. Risky actions wait for your tap

The agent can read everything and change what it created itself. It pushes to its own branches freely, but asks before merging or pushing to main. It also asks before sending anyone an email.

Tapping Allow all the time gets tiring. So you can allow one kind of action for good, or give the agent an hour for all changes to one service or repository. Deletions still ask.

Allow/Deny request in Telegram

3. The agent lives in a container

I already ran my agents in a sandbox or a Docker container. den does it for you, on your computer or a server.

On a Mac the isolation is stronger. On Linux a container shares the kernel with the host. With Apple container, each container gets its own lightweight VM with its own kernel.

It's also light. At idle, den itself takes about 20 MB and the whole container about 72 MB. The headless browser and speech-to-text start only when a task needs them.

What it doesn't protect against

  • The agent has full internet access inside the container. A prompt injection can make it leak whatever it reads.
  • A breached provider still means rotating your keys.
  • An OS-level vulnerability could let the agent escape its permissions and reach your secrets.

Nothing is 100% safe. The goal is to make an attack much harder.

Try it

den works with most model providers and subscriptions. Claude Pro/Max runs through the official claude CLI.

Setup is one command. You need a Telegram bot (the current interface) and a model key.

curl -fsSL https://raw.githubusercontent.com/unsady/den/main/install.sh | sh
Enter fullscreen mode Exit fullscreen mode

https://github.com/unsady/den

The project is young, and I want to hear where this threat model leaks. And a question for you. What would you let an agent do without asking?

Top comments (0)