Metera cover: “For developers. Your agent should never hold the key.” over a field of green dashes
December 2, 2026MeteraFor developers

Your agent should never hold the key

Custody design for autonomous agents. For developers. Includes code. 9 minute read.

Most agent tutorials on Solana start the same way:

const agent = Keypair.fromSecretKey(bs58.decode(process.env.AGENT_PRIVATE_KEY!));

It works. It is also the single most dangerous line in the project. From that moment, anything that can influence the agent can spend everything the key controls. Not just the agent’s logic: every prompt, every tool result, every web page it reads.

This article is about the alternative. The agent keeps the decision. It gives up the key.

The threat model nobody writes down

A traditional backend has a fixed set of code paths. An agent doesn’t. Its behavior is shaped by text it reads at runtime, and some of that text is written by people who would like your money. Four failures show up again and again:

  • Prompt injection. A web page, a token description or a tool result contains instructions, and the agent follows them with a key in hand.
  • A leaked environment. The key sits in an environment variable that ends up in a log line, a crash report or a debugging session.
  • A runaway loop. A bug, not an attacker, signs the same kind of transaction over and over until the balance is gone.
  • A compromised dependency. Any package running in the same process can read the same environment the agent can.

None of these require the model to be wrong. They only require the key to be reachable from wherever the model’s output flows.

Separate deciding from signing

The fix is an old one from security engineering: the component that decides should not be the component that can act without limits. Split the path in three.

  • The agent produces intent, or an unsigned transaction. It holds no key and has no way to sign.
  • A policy check reads what the transaction would actually do and compares it with rules you wrote down in advance.
  • A signer held outside the agent’s process signs only what passed. Nothing else reaches it.

In code, the agent’s side shrinks to a request and a decision:

// the agent never sees a key: it sends what it wants, and reads a decision
const res = await fetch(PREFLIGHT, {
  method: "POST",
  body: JSON.stringify({ transaction, intent, policy }),
});
const { decision } = await res.json();
if (decision !== "allow") return; // refused before anything was signed

What the policy should check

  • Programs: only the protocols this agent is meant to touch.
  • Amounts: a maximum per transaction, in plain numbers.
  • Daily ceilings: so a loop can’t spend everything before a person looks.
  • Recipients: an allowlist where the use case has one.
  • Hidden authority: unlimited token approvals and delegate or owner changes, wherever they sit in the route.

Check outcomes, not labels. An instruction named “swap” that also grants an unlimited approval should be refused for the approval, whatever it is called.

Where the key lives

The key belongs in secure hardware it can’t be exported from, such as a Turnkey enclave, with signing only reachable through the policy-checked path. Your backend asks for a signature; it never holds the material that produces one.

What you give up

One extra step before every signature, and the ability to sign anything you like from anywhere. That is the point. An agent that can only sign what passed your rules can be left running without someone watching it.

Agents decide. Metera executes.