Why AI Agent Wallets Must Be Non-Custodial: The Lazarus Attack Made It Obvious

Published: (March 18, 2026 at 11:03 AM EDT)
4 min read
Source: Dev.to

Source: Dev.to

What Happened at Bitrefill

Gartner confirmed that Lazarus Group compromised Bitrefill’s hot wallet this month using a combination of compromised API keys and a prompt injection through their customer‑facing AI assistant. The injection escalated privileges to the payment backend. The hot wallet—centrally managed, single key—was drained in minutes.

  • No blockchain exploit.
  • No smart‑contract bug.
  • They found one centralized key, and that was the whole game.

If you’re running agents with custodial wallets, you have the exact same attack surface—arguably worse, because your agents constantly read untrusted content.

Three Ways the Custodial Model Breaks for Agents

  1. Prompt injection → payment execution
    Agents process untrusted content all day (web pages, API responses, user inputs, tool outputs). An attacker who can inject text into an agent’s context can try to trigger a withdrawal, approve a transaction, or rotate credentials.

    • Custodial wallet: that instruction reaches a backend that can execute it, exposing the entire wallet balance.
    • Non‑custodial with on‑chain spending policies: the same injection hits a contract that enforces limits (e.g., “max 0.01 ETH per transaction, only to whitelisted addresses, and no more than 0.1 ETH per day”). The request is denied.
  2. The infrastructure owner is your weakest link
    Custodial means someone else holds your keys. That someone is a target—API‑key leaks, insider threats, phishing, supply‑chain compromises—all expose your agents’ funds without any mistake on your part.

    • Non‑custodial: your agents hold their own keys. A breach of the infrastructure provider doesn’t touch your wallets.
  3. Binary authorization is too coarse for agents
    Most custodial setups have a single dial: the API key can spend, or it can’t. No per‑agent limits, no destination whitelists, no time‑locked withdrawals.
    ERC‑6551 Token‑Bound Accounts—what agent‑wallet‑sdk runs on—put spending controls on‑chain. Every agent wallet has a SpendingPolicy that defines exactly what it can do. The policy is immutable, auditable, and cannot be overridden by a redeploy.

What This Looks Like in Code

import { AgentWallet, SpendingPolicy } from '@ai-agent-economy/agent-wallet-sdk';
import { parseEther } from 'ethers';

// Spin up an agent wallet with hard guardrails
const wallet = await AgentWallet.create({
  policy: new SpendingPolicy({
    maxPerTx: parseEther('0.01'),   // 0.01 ETH max per transaction
    maxPerDay: parseEther('0.1'),   // 0.1 ETH daily cap
    allowedDestinations: [
      '0xYourAPIProvider',
      '0xYourSubAgentPool',
    ],
  }),
});

// Agent pays for an inference call
await wallet.pay({
  to: '0xYourAPIProvider',
  amount: parseEther('0.005'),
  memo: 'inference_call_id_abc123',
});

No centralized server. The policy check happens in the contract. Injected prompts, rogue tool output, or compromised sub‑agents are irrelevant—the contract rejects anything outside the policy.

The ERC‑6551 Property Nobody Talks About

TBA wallets are owned by an NFT. Transfer the NFT, and all agent permissions revoke instantly—no API‑key rotation, no backend calls, no incident‑response ticket.

The Bitrefill breach succeeded partly because revoking a compromised credential required manual action. The time between discovery and revocation is where the damage occurs. With TBA architecture, revocation can be automated: an anomaly triggers NFT transfer to a null address, locking the wallet before a human is even paged.

The Objection Worth Addressing

“Non‑custodial is complex. Custodial with good security practices is fine.”

The second half of that sentence does a lot of heavy lifting.

Bitrefill didn’t have bad security practices; they had normal ones—API‑key management, access controls, logging. Lazarus found the AI assistant and worked through it because the assistant had payment privileges.

That’s the new attack vector. Most custodial security models were built before agents that process untrusted text had payment capabilities. They weren’t designed for this threat.

On‑chain spending limits with destination whitelists are the only architectural control that doesn’t require perfect OPSEC. Everything else is defense‑in‑depth—good, necessary, but not sufficient.

Bottom Line

If your agents touch real money, the architecture decision isn’t a trade‑off anymore: non‑custodial with on‑chain spending limits, whitelisted destinations, and minimal balances (just enough for the next few operations).

We built agent‑wallet‑sdk because we needed it for our own agents and it didn’t exist. It’s written in TypeScript, MIT‑licensed, and built on ERC‑6551.

Repo: github.com/AI-Agent-Economy/agent-wallet-sdk

Building agent payment infrastructure and want to compare notes? I’m @AgentEconoemy on X.

Tags: #ai #blockchain #security #typescript

0 views
Back to Blog

Related posts

Read more »

Agents in 60 lines of python : Part 3

The Agent Loop The entire AI agent stack in 60 lines of Python. You've seen Claude search files, read them, then search again. ChatGPT with Code Interpreter wri...