How to stop an AI agent from signing a drainer

An onchain agent with a hot wallet will eventually be shown a malicious transaction or permit. Here is how to make sure it never signs one.

Updated 23 November 2026 (UTC) · 7 min read

An AI agent that trades, pays or rebalances needs a wallet it can sign with. That makes it a target. It reads web pages, API responses and messages from other agents, and any of them can carry a prompt injection or simply a bad address. A model that is 99% careful still signs the one transaction that empties the wallet.

The fix is the same as for people: never sign what you have not simulated, and let a rule, not the model, have the last word.

What actually drains agent wallets

  • Unlimited approvals to a contract the attacker controls, often hidden inside a "swap" or "claim".
  • Permit and Permit2 signatures. They cost no gas and never appear as a transaction, so a check that only looks at transactions misses them.
  • Transfers to a lookalike address taken from a poisoned message or page.
  • Honeypot tokens the agent can buy but never sell.
  • Reverting or oversized transactions that waste funds or break the agent's own limits.

Five layers, cheapest first

  1. A separate wallet holding only what the agent needs this week.
  2. Simulate every transaction on the latest block before signing, and look at what actually moves: tokens out, approvals given, the revert reason.
  3. Check signatures too, with the same care: Permit, Permit2, Seaport orders and personal_sign.
  4. A policy outside the model: spending caps per transaction, allowed targets, trusted spenders, no unlimited approvals. The model cannot talk its way past code.
  5. A hard rule: never sign on DENY, and treat a failed check as DENY.

With Heimdall Shield over MCP

Claude, Cursor and any MCP agent get the checks as tools. Add the server to the client's config:

{
  "mcpServers": {
    "heimdall": { "command": "npx", "args": ["-y", "@heimdallfund/mcp"] }
  }
}

The server tells the model to check every transaction and signature before signing and never to sign on DENY. See MCP server for every client.

In your own agent code

With the Vercel AI SDK, LangChain or ElizaOS, @heimdallfund/agent-kit adds the checks as native tools. Give it the wallet and the agent gets heimdall_safe_send, which only sends what Shield allows:

import { generateText } from "ai";
import { heimdallAiTools } from "@heimdallfund/agent-kit/ai-sdk";

const { text } = await generateText({
  model,
  tools: heimdallAiTools({
    wallet,
    policy: {
      maxTokenOut: { "0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168": "500000000" }, // at most 500 USDG per transaction
      denyUnlimitedApprovals: true,
    },
  }),
  prompt: "Swap 50 USDG for NVDA",
});

Or call it directly before you send anything:

import { HeimdallShield, guardedSend } from "@heimdallfund/sdk";

const shield = new HeimdallShield({ apiKey: process.env.HEIMDALL_API_KEY });
const { hash } = await guardedSend(wallet, { to, data, value }, { shield }); // throws HeimdallDenied unless ALLOW

Checklist

  • The agent's wallet holds only working funds.
  • Every transaction and every signature request is checked before signing.
  • Spending caps and allowed targets live in code, not in the prompt.
  • DENY, or no answer, means no signature.
  • You scan the agent's wallet for leftover approvals every week.

More guides