# How to give an AI agent API keys without handing them over

Source: https://osevel.com/learn/api-keys-for-ai-agents/ · reviewed 2026-11-28

> Do not leave keys in .env files an agent can read. Give a command its keys only while it runs, hide them in what the agent reads back, and where you can, give the agent a stand-in that is swapped for the real key only on the way to the service the key belongs to.

## Where keys leak

- A .env file in the project, which any agent in the folder can read.
- A key pasted into a chat, or committed by accident.
- A key printed in a command’s output, which the agent then reads.
- An AI tool’s MCP configuration file, with keys in plain text.

## What works in general

- Keep keys encrypted, not in plain files.
- Give a program its keys for one run, in its environment, not on disk.
- Hide keys in the output the agent reads.
- Bind a key to the address it is for, so that a copy is worthless anywhere else.

## What OsVault does

- Your password becomes the key on your device and never reaches us; our cloud stores only ciphertext.
- osevel vault run -- <command> gives the command its secrets as environment variables for that run, with the values masked in its output.
- A locked key reaches the program as a stand-in; a local proxy puts the real key in only on requests to the address it is bound to. Keys of known services (Stripe, OpenAI, Anthropic, GitHub and others) are locked when you save them; any other key can be locked to the address you give.
- osevel vault agent <tool> prints the MCP configuration for Claude Code, Cursor and other tools. OsBox keeps MCP servers’ keys in OsVault, not in the tools’ config files.
- Share a vault by typing a teammate’s email; the first time, you compare a short code once.

## Questions

### Can the agent still use a locked key?

Yes, at its own service and within what the key allows there, but it cannot copy it anywhere else. A key that can create other keys can be used to create one, so use the service’s restricted keys where it has them.

### Is masking enough for keys that are not locked?

It protects against accidents, not against a determined agent: a program that holds the real value can send it anywhere. Lock keys where you can.

### Which systems does it run on?

macOS, Windows and Linux. With the Osevel service installed (macOS and Linux), keys are opened by the service, out of the agent’s reach.
