agentleFS
SirCharanSirCharan/claude-code-harness/skills/llm-trading-agent-security/SKILL.md

llm-trading-agent-security

Skill0 starsChanged 5 months agoMITView on GitHub

Security patterns for LLM-driven trading agents that can place real orders — for centralized-venue systems (REST APIs + keys, not on-chain wallets). Covers prompt-injection defense on signal prompts that ingest external data, hard spend/position limits, pre-submit order validation, circuit breakers (drawdown/consecutive-loss halts), key handling, and audit logging. Use when building/auditing an executor, giving an LLM order-placement authority, or reviewing how external market data/news enters a decision prompt. Trigger on: "trading bot security", "executor safety", "can the agent place orders", "prompt injection in signals", "spend/position limit", "circuit breaker", "kill switch". Adapted from ECC (affaan-m/ECC, MIT), re-scoped for centralized REST trading.

9 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use pdf.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • AnthropicSkill

    pdf

    Comprehensive PDF manipulation toolkit for extracting text and tables, creating new PDFs, merging/splitting documents, and handling forms. When Claude needs to fill in a PDF form or programmatically process, generate, or analyze PDF documents at scale.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

4 rules. 0 are common, 1 is distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 9 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Never blind-inject token names, headlines, webhooks, or social feeds into the decide prompt.

    line 32
  2. Very specific:

    Before sending an order: assert symbol is tradable, side/qty/price within sane bounds, leverage ≤ allowed, reduce_only set on SL/TP, and …

    line 46
  3. Very specific:

    Keep an env kill-switch (pattern: *_ENABLED=0 / ACTIVE_ASSETS=none) that stops generation+execution.

    line 59
  4. Distinctive:

    Use a dedicated trading key with least privilege.

    line 63

“Common” is measured: kept by at least 6 in 10 of the 9 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

LLM Trading-Agent Security

Trading agents have a harsher threat model than normal LLM apps: an injection or a bad tool path turns directly into money lost. Layer independent controls — no single check is enough. (This drops the on-chain/MEV/wallet-signing parts of the original ECC skill and keeps what applies to centralized REST-API executors with your exchange/broker.)

1. Treat prompt injection as a financial attack ✅

Signal prompts ingest external data (news, social, market feeds, other-venue data). Sanitize anything that could carry an instruction before it enters an execution-capable prompt.

INJECTION = [r'ignore (previous|all) instructions', r'new (task|directive|instruction)',
             r'system prompt', r'(buy|sell|close|transfer|withdraw) .{0,40}(now|immediately|all)']
def sanitize_external(text: str) -> str:
    for p in INJECTION:
        if re.search(p, text, re.I): raise ValueError(f"possible injection: {text[:100]}")
    return text

Never blind-inject token names, headlines, webhooks, or social feeds into the decide prompt. Keep the decision schema strict (direction/size/levels) so free text can't become an order.

2. Hard spend / position limits (independent of model output) ✅

Enforce in code, separate from whatever the LLM says. Your existing risk gates and reduce-only SL+TP should be guards in code, not conventions.

MAX_SINGLE_NOTIONAL, MAX_DAILY_NOTIONAL = Decimal("15000"), Decimal("60000")
def check(amount):  # raise before any order submit
    if amount > MAX_SINGLE_NOTIONAL: raise SpendLimit(f"{amount} > single cap")
    if day_total() + amount > MAX_DAILY_NOTIONAL: raise SpendLimit("daily cap")

3. Validate before submit (the centralized analog of "simulate") ✅

Before sending an order: assert symbol is tradable, side/qty/price within sane bounds, leverage ≤ allowed, reduce_only set on SL/TP, and the computed notional matches the intended size (catch decimal/lot-size bugs). Reject on mismatch — never submit an order you didn't fully re-derive.

4. Circuit breakers / kill switch ✅

Halt on drawdown or invalid state. Formalize your existing risk gates and per-app pause flags:

MAX_CONSEC_LOSSES, MAX_HOURLY_LOSS = 3, 0.05
def guard(consec, portfolio, hour_start):
    if consec >= MAX_CONSEC_LOSSES: halt("consecutive losses")
    if hour_start <= 0: halt("invalid hour_start"); return
    if (portfolio - hour_start)/hour_start < -MAX_HOURLY_LOSS: halt("hourly drawdown")

Keep an env kill-switch (pattern: *_ENABLED=0 / ACTIVE_ASSETS=none) that stops generation+execution.

5. Key handling & audit ✅

Keys from env / your secret store, never in code or logs; the secret-scan hook backstops prompts. Use a dedicated trading key with least privilege. Audit-log every decision (including rejected/not-sent), not just successful orders — you can't debug or trust an executor whose refusals are invisible.

Pre-deploy checklist

  • external data sanitized before the decide prompt - [ ] spend/position limits enforced in code, independent of model output - [ ] order re-derived & validated before submit (notional, lot size, reduce-only) - [ ] circuit breakers + env kill-switch wired - [ ] keys from env, never logged - [ ] every decision audit-logged (sent and not-sent) - [ ] paper-mode path tested before live.

Sources

Adapted from ECC skills/llm-trading-agent-security (MIT), re-scoped from on-chain wallets to centralized REST trading; aligns with reduce-only SL+TP, risk gates, kill-switch flags, and env-based secret handling.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.