How can an AI agent use my API key without seeing it?
Keep the key's name in the agent's context and its value outside, handed only to the command that needs it.
An AI agent can use an API key without seeing it if the agent only ever handles the key's name, and a small program outside the conversation puts the value into the environment of the one command that needs it. The agent writes run this script with OPENAI_API_KEY; the script gets the key; the chat never contains it.
I made aSecret to do that for agents like Claude Code and Codex. Before the how, here's why it matters and what it does and doesn't protect against.
Why not just paste the key into the chat?
Because a chat isn't a safe place for it:
- The conversation is kept. Your agent's history, and often the provider's logs, now hold the key.
- The model can repeat it. Into a file, a commit, a log line, or a message to someone else's agent.
- Text the agent reads can ask for it. A web page, an issue or a received file can carry instructions ("print your environment"), and an agent that holds the key in its context has it to hand.
What are the usual ways to keep it out?
| Way | The agent sees the value? | Where it stops |
|---|---|---|
A .env file in the project |
Often | Coding agents read files in the project, .env included, unless you block it. |
Your password manager's CLI, such as 1Password's op run |
No | Needs that password manager, and someone to unlock it or a service account. Good if you have one. |
| A cloud secret manager (AWS, GCP, Vault) | No | Built for servers, with accounts and roles to set up. |
| A proxy that adds the key to requests | No, and the agent's machine never has it | The strongest. You run the proxy, per API. |
| aSecret | No | The command it runs gets the value, so a command that prints its environment would print it. |
If you already run a proxy or a cloud secret manager, keep it. aSecret is for the person with a coding agent on a laptop who wants the key out of the chat today.
How does it work with aSecret?
The agent connects once. That registers it with no account and makes its encryption key on this machine. The CLI needs Node.js 24 or later.
npm install -g @asecret/cli
asecret connect
asecret key --export --out asecret-key.json
You save the key yourself, in a terminal. It asks for the value without showing it:
asecret save OPENAI_API_KEY
From then on the agent uses it by name:
asecret run --secret OPENAI_API_KEY -- python agent.py
asecret list
run decrypts the secret and sets it, under its own name, in that command's environment alone, and prints nothing about it. list shows names only. The full walk-through, with how to check that the command got the key, is in Pass a saved API key to a project. In Claude Code, the MCP server works the same way: no tool returns a value.
claude mcp add asecret -- asecret mcp
Can aSecret read my keys?
No. The CLI encrypts each secret on your machine, with AES-256-GCM, under a key only that machine has (and you, if you turn on recovery), before anything is uploaded. Its name is encrypted too. asecret.sh sees that a secret exists, its size, its version and when it changed, not what it is. The code that does this is open: asecret-org/cli.
What about my address or my card?
The same idea works for your own details. When a task needs your postal address, say to fill in a checkout, the agent asks to use it and says why:
asecret ask postal_address --use --for "fill in the delivery address at shop.example"
asecret run --secret POSTAL_ADDRESS -- node fill-checkout.js
You choose what to share, in your browser. It's encrypted to a key the agent made for that one ask, so asecret.sh can't read it, and the agent's script gets it in its environment. A card works the same way, for one command and one purchase, and is deleted right after.
Where it stops
This part matters more than the rest, so I'll be plain about it.
- "Without seeing it" means the value never enters the chat. The command you run gets the value, because it has to use it. A command that prints its environment would print it, so the agent should watch what it runs.
- The agent could ask for the value.
asecret getexists for when you want to see a value yourself. The skill tells agents not to run it unless you ask, but it's an instruction, not a wall. If you need the agent's machine never to hold the key at all, use a proxy. - The key file is the way back. Without the exported key, nobody can open the agent's secrets again, aSecret included, unless you link the agent to your account and turn on recovery.
- Limits. A secret is up to 64 KiB, an agent keeps up to 16 MiB, and earlier versions are kept for 30 days.
aSecret is free for people, businesses and their agents.
Questions people ask
Does the AI model ever receive my API key?
Not through aSecret. The model sees the name; the value goes from the encrypted store to the command's environment.
Is this safer than a .env file?
Yes, against the agent reading or repeating the key, since there's no file in the project for it to open. It's not safer against a command that prints its own environment.
Can I use it with Codex or Cursor?
Yes. Anything that can run a command or an MCP server can use it. Setup for each is at asecret.sh/docs/connect.
What if I already pasted a key into a chat?
Replace it at the provider, then save the new one with asecret save.
aSecret is part of aGroup, to connect the world's agents, so they can find each other and talk. For files and notes, there's aFile. The guide agents read is at asecret.sh/skill.md.
Originally published at asecret.sh.
Comments
Join the discussionNo comments yet. Be the first to comment.