AI & Agents

How-To: Give Your AI Coding Agents Scoped, Short-Lived API Keys and Keep Them Out of Reach

Leave a comment

The Docker Sandboxes key-leak flaw is a good excuse to tighten up how agents get credentials. This is the setup I use for my own bots. Adjust names and paths to your setup.

1. One key per agent, per project

Don’t hand every tool your main key. Make a separate key for each agent or project in the provider’s console (OpenAI and Anthropic both support project or workspace keys), set a monthly spend limit, and name it so you know what to kill. For GitHub, use a fine-grained token limited to the repos it needs, with an expiration date.

2. Keep keys out of your shell profile

Find stragglers first:

rg -n --hidden -g '!.git' 'sk-[A-Za-z0-9_-]{20,}|github_pat_|ghp_' ~
env | grep -iE 'api_key|token' | cut -d= -f1

Then store each key in its own file only you can read, and load it just for the session that needs it:

mkdir -p ~/.config/agent-secrets && chmod 700 ~/.config/agent-secrets
printf '%s' 'PASTE_KEY' > ~/.config/agent-secrets/project-a.key
chmod 600 ~/.config/agent-secrets/project-a.key
ANTHROPIC_API_KEY=$(cat ~/.config/agent-secrets/project-a.key) claude

Better yet, use your desktop keyring (secret-tool) or pass instead of plain files.

3. Review sandbox and plugin approvals

If you use Docker Sandboxes, upgrade to 0.55.0 and read ~/.config/sbx/credentials.yaml. Remove bindings for third-party kits you don’t actively use. Pin kits, plugins and MCP servers to a fixed commit instead of a moving branch.

4. Rotate on a schedule

Put a calendar reminder to rotate agent keys every 90 days, and right away if a kit or plugin you approved changed. Revoke the old key, don’t just make a new one.

Nothing here is fancy. It’s just making sure one bad update costs you one cheap, revocable key instead of everything.

God Bless, and May the Source Be with You!

References & Further Reading

Subscribe (RSS) Follow AI & Agents via RSS

Leave a note

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.