← All guides AI Release
RU Subscribe to @ai_releaseorg

How to protect exchange API keys from an AI agent: isolation, scopes, and rotation

Updated: 22.11.2026 · AI Release · @ai_releaseorg
How to protect exchange API keys from an AI agent: isolation, scopes, and rotation

Guide passport

Illustration: Guide passport
Illustration: Guide passport

An exchange API key is not a forum password. If it leaks, the damage is measured in order history and balance, not in a password reset. This guide is about reducing the cost of a leak to near zero before it happens.

How an exchange key differs from an LLM key

An LLM key spends tokens. An exchange key moves money. The permission model defines everything:

PermissionLLM keyExchange key
Read datayesyes
Create operationsgenerate textreal-money orders
Withdraw fundsno**often enabled by default**
Cost of a leaka token billthe subaccount balance

So the defense is not “hide the string”. It is shrinking the permission set. Even a stolen key without withdrawal rights and with an IP allowlist is a bounded problem, not a lost deposit.

Threat model: how keys leak in 2026

The lesson: the threat is almost never clever cryptography. It is the permissions you granted and the channels through which the secret is reachable.

Step 1. Create a key with the minimum scope

Where the exchange supports it, create a subaccount and a separate key for trading only.

subaccount: agent-hot-01
key label:  executor-01
scopes:     read, trade
withdraw:   disabled
ip allow:   203.0.113.10
symbols:    BTC/USDC, ETH/USDC

Why it matters: if the key leaks, the attacker cannot withdraw. The worst case is a trading loss bounded by your limits. Painful, but survivable.

Step 2. Isolate the secret from the agent

The core rule: the key never enters the model context, the logs, or tool responses. A model can ask to “show the config”, and if the key sits in a file the agent can read, it ends up in chat or history.

import os, re

KEY = os.environ["EXCHANGE_TRADE_KEY"]  # executor only

def redact(text: str) -> str:
    # keep the key out of logs and model responses
    return re.sub(r"(?i)(api[_-]?key|secret|token)(\s*[:=]\s*)\S+", r"\1\2***", text or "")

Why it matters: even if the model errs and tries to print the config, it will not see the key. The secret lives in the executor process, not in shared context.

Step 3. Restrict network and processes

Illustration: Step 3. Restrict network and processes
Illustration: Step 3. Restrict network and processes

Secret isolation is useless if the agent container can reach the whole server and every domain.

# docker-compose.yml (excerpt)
services:
  executor:
    build: ./executor
    env_file: ./secrets/executor.env      # chmod 600, not in git
    read_only: true
    networks: [exchange_net]
    # no docker.sock, no home directories
  analyst:
    build: ./analyst
    networks: [data_net]
    # no exchange keys here at all

networks:
  exchange_net: {}
  data_net: {}

Why it matters: a compromised analyst cannot reach the key and cannot reach the exchange directly. It can only produce proposals that the controller checks.

Step 4. Set up rotation and monitoring

A key with no expiry is a key forever. Make rotation routine, not a reaction to an incident.

# quick check that the old key is dead
curl -s -H "X-API-KEY: $OLD_KEY" https://api.exchange.example/account | head
# expected: 401 / invalid key

Why it matters: rotation limits the window in which a leaked key is useful. Monitoring catches the leak before the balance does.

Step 5. Runbook: what to do on a leak

Act in order, and do not rely on the model.

1. Revoke the key in the exchange panel — immediately, not “after the review”.

2. Stop the executor with an independent kill switch.

3. Check history: orders, cancellations, withdrawal attempts, new IPs.

4. Assess the damage from actual operations, not from the agent’s logs.

5. Rotate the remaining keys if they could have been exposed too.

6. Check the infrastructure: open ports, admin panels, container access.

7. Write the postmortem: how the key became reachable and what now closes it.

If the key had withdrawal rights, treat the funds as lost until proven otherwise and act as during an incident, not a suspicion.

Checklist

Troubleshooting

The bot stopped trading after enabling the IP allowlist. The executor goes out through a different egress IP (VPN, NAT, a second server). Fix: find the actual outbound IP and add it, do not disable the allowlist.

The key shows up in application logs. The cause is logging environment variables or full API responses. Fix: apply redact() on every logging path and check that .env does not appear in docker inspect or error reports.

Some services broke after rotation. They all shared one key. Fix: issue a separate key per service from the start and rotate them one by one.

The agent “sees” the key in its context. The key sits in a file the agent’s tool can read, or in the system prompt. Fix: remove the key from reachable paths and from the prompt, and keep it only in the executor process.

FAQ

Is disabling withdrawals enough? It is the most important step, but not the only one. Without an IP allowlist and secret isolation, the key can still be used for losing trades or balance reconnaissance.

Can I keep the key in an environment variable? Yes, if only the executor can read that environment. But do not pass it to the agent, do not log it, and do not commit it to git.

Do I need a separate key if there is only one agent? Yes. A per-service key simplifies rotation and limits the blast radius: revoking one does not stop everything.

What matters more: rotation or the allowlist? Both. The allowlist narrows the source, rotation shortens the lifetime of a leaked key. Each is weaker alone.

Further reading

Illustration: Further reading
Illustration: Further reading

🤖 AI summary

AI Release Knowledge Layer
Machine-readable description · Version 1.0

Status: practical guide. Some statements come from vendors; verify in your environment.

1. Summary

Step-by-step protection of exchange API keys from an AI agent: least privilege, secret isolation, egress, rotation, and a leak runbook.

Inside: direct answers, key facts, entities, context, reliability, unknowns and sources.

Machine data: Citation Map JSON · JSON-LD · Semantic Embeddings — separate stage.

Full Knowledge Layer: sections 2–8

2. Direct answers

What is this guide about?
Step-by-step protection of exchange API keys from an AI agent: least privilege, secret isolation, egress, rotation, and a leak runbook. → details (AR-GUIDE-KAKZASHCHI-001)
How to do it?
Step 1. Create a key with the minimum scope → Step 2. Isolate the secret from the agent → Step 3. Restrict network and processes → Step 4. Set up rotation and monitoring → details (AR-GUIDE-KAKZASHCHI-004)
Which topics does it cover?
API-ключи биржи, защита API-ключей, ИИ-агент, торговый бот, ротация ключей, изоляция секретов → details (AR-GUIDE-KAKZASHCHI-002)

3. Key facts

  1. An exchange API key is not a forum password. If it leaks, the damage is measured in order history and balance, not in a password reset. This guide is about reducing the cost of a leak to near zero before it happens. — evidence; status: анализ AI Release.
  2. An LLM key spends tokens. An exchange key moves money. The permission model defines everything: — evidence; status: анализ AI Release.
  3. So the defense is not “hide the string”. It is shrinking the permission set. Even a stolen key without withdrawal rights and with an IP allowlist is a bounded problem, not a lost deposit. — evidence; status: анализ AI Release.
  4. The lesson: the threat is almost never clever cryptography. It is the permissions you granted and the channels through which the secret is reachable. — evidence; status: анализ AI Release.

4. Entities

EntityTypeRole
exchange API keysтема/инструментупоминается в заголовке, TL;DR или разделах гайда
AI agent securityтема/инструментупоминается в заголовке, TL;DR или разделах гайда
key rotationтема/инструментупоминается в заголовке, TL;DR или разделах гайда
secret isolationтема/инструментупоминается в заголовке, TL;DR или разделах гайда
trading bot securityтема/инструментупоминается в заголовке, TL;DR или разделах гайда
Telegramплатформа/технологияупоминается в заголовке, TL;DR или разделах гайда
Dockerплатформа/технологияупоминается в заголовке, TL;DR или разделах гайда

5. Context

  • Guide — describes → How to protect exchange API keys from an AI agent: isolation, scopes, and rotation (AR-GUIDE-KAKZASHCHI-001).
  • Guide — includes step → Step 1. Create a key with the minimum scope (AR-GUIDE-KAKZASHCHI-001).

6. Reliability

Confirmed

No independent confirmation is provided; source claims and editorial conclusions are separated below.

Source claims

  • Product features, versions, prices and limits come from vendors and the guide.
  • Commands and steps are recommendations, not guaranteed results.

AI Release analysis

  • Structure, comparison and selection criteria are editorial.
  • The guide does not replace an independent audit or legal advice.

7. Unknowns

  • Current versions, prices and limits.
  • Independent benchmarks and quality checks.
  • Terms of use and data policy.

8. Sources

SourceTypeRole
api.exchange.exampleвнешний источникссылка из тела гайда

Cite as: AI Release. Как защитить API-ключи биржи от ИИ-агента: изоляция, права и ротация. ai-release.org.