Blog

Is It Safe to Put API Keys in an Agent Sandbox?

ยท Jonathan Fishner
Is It Safe to Put API Keys in an Agent Sandbox?

Say you have forty bugs to fix. You could always rent forty machines for that, but setting them up was a project of its own, so almost nobody did. Today you ask Claude Code. It starts forty sandboxes, puts an agent in each one, and they all work at the same time. You go get coffee.

That's why everyone is talking about sandboxes right now, and they're right to. A machine starts in a few seconds and costs almost nothing, so Claude Code or Cursor can create one when it needs it and throw it away after. An agent can work for hours somewhere that isn't your laptop. With snapshots you set a machine up once and start a thousand copies. We run our own agents in them every day.

But one question tends to get skipped. The agent in that sandbox has to talk to GitHub, to your database, to Stripe. For that it needs your keys. Where do you put them?

We build an agent vault, so we spend most of our time on this question.

What a sandbox protects, and what it doesn't

The pitch is isolation, and it's true. The agent can delete every file on the machine and your laptop won't notice.

Look at which direction that protects, though. It keeps the agent away from your computer. It does nothing about the things the agent is supposed to reach: the repo, the tickets, the database. For those it needs credentials, so in most setups the first thing that happens after a sandbox starts is that someone copies real keys into it.

Where the keys end up

Usually in several places at once:

  • Environment variables and files. Any process in the sandbox can read them, including whatever the agent decides to run.
  • Snapshots. If the key was there when you saved the machine, it's in every machine started from it.
  • Logs. Agents print things. Sometimes they print the environment.

What actually goes wrong

You might picture someone breaking into the sandbox. What usually happens is simpler: the agent reads something it shouldn't trust.

Agents read web pages, issues, the README of a dependency. One of them contains an instruction, and the agent follows it.

The agent had the keys and the sandbox had open internet. Nothing was hacked. The agent was asked, and it helped.

Then you rotate a key that lives in forty places.

Send me your keys.Sure, sent!

The fix: keep the key outside

So, is it safe? Running the agent in a sandbox is. Putting a real key in there with it is the part to avoid.

The key stays outside. The agent sends its requests as usual, and something that sits between the sandbox and the internet adds the key on the way out. The agent gets its answer and never holds the key. This isn't our invention: Docker's sandboxes work this way, and OpenAI's guide recommends the same thing.

That solves half of it. A key that can't be stolen can still be used badly: an agent that may delete a repo can still delete it. We wrote about that limit in what a credential vault can and can't do. So the place that adds the key should also decide what each agent is allowed to do.

How we do it at OneCLI

OneCLI is an agent vault: it holds your keys, and it is that place in the middle. The sandbox connects to it once, when it starts. From then on every request the agent makes passes through OneCLI, which checks it, adds the right key and sends it on.

Three things come with that:

  • Connecting apps is quick. For dozens of apps, like GitHub, Gmail, Linear and Stripe, you sign in once and that's it. There is no key to copy anywhere. For anything else, you paste an API key into the vault.
  • Each agent gets its own permissions. For every action you pick one of three: always allow, ask me first, or never.
  • Risky actions wait for you. A refund, a delete, a push to main: the request stops until a person approves it.
QA agent
  • Read issuesAlways allow
  • Merge to mainAsk me first
  • Delete the repoNever

And if one agent misbehaves, you cut it off with one click. No key has to change.

It works with the sandboxes people already use, like E2B and Boat, and with plain Docker or any Linux machine. You keep the speed and the low cost of sandboxes, and your keys stay out of them.