Claude Code vs Cursor (vs Codex & Grok Build) for Building Trading Bots: The Guardrails Compared

KalshiPolymarket US Comparison + setup prompt

Short answer: Any of the four can write a Kalshi or Polymarket US bot; none can make one profitable. The difference is guardrails. Claude Code is terminal-first with deep hooks and deny rules. Cursor is an AI code editor with rules, hooks and .cursorignore (which doesn't cover terminal or MCP tools). Codex starts with the strictest defaults: an OS sandbox with network off, though it can still read key files outside the project. Grok Build reuses Claude configs once you trust the folder, but its sandbox is off by default and its hooks fail open.

What are the key facts?

  • Claude Code vs Cursor in one line: Claude Code is a terminal-first agent (also in IDEs and a desktop app); Cursor is an AI code editor with an agent built in. Both read rules files, support skills and run hooks.
  • Defaults matter most. Codex runs commands in an OS sandbox with network off. Claude Code's and Grok Build's sandboxes are off until you turn them on; Cursor asks before terminal commands unless you pick a Run Mode.
  • Keys outside the project aren't safe by default. Codex's sandbox read our fake key one folder up, Cursor reads outside the workspace without asking, and Grok's workspace profile reads everywhere. Each tool needs its own deny setting.
  • Secret files: Claude Code and Grok Build have deny rules (Read(**/.env)). Cursor's .cursorignore blocks Agent, Tab and @-mentions, but not terminal or MCP tools.
  • Hooks partly travel. Cursor and Grok Build load Claude Code hooks; Codex uses a near-identical PreToolUse format. Grok Build 1.0.70 refused a Cursor hook. Only Claude Code and Cursor can block when a hook crashes or times out.
  • Rules files: AGENTS.md now works in all four (Claude Code since v2.1.277, when there's no CLAUDE.md). Cursor's .mdc rules aren't loaded by Grok Build.
  • Whatever you pick, position limits and the kill switch belong in the bot's code. No tool setting replaces them.
DifficultyBeginner
Time15 min read · 30 min setup
Cost$0 setup · your AI subscription
Works withClaude Code, Cursor, Codex, Grok Build

What will you build?

Pick the AI coding tool that fits how you work, then turn on its guardrails before it touches a trading bot: rules file, secret blocking, a hook or two, and the sandbox if it has one.

Who is it for?

People choosing between Claude Code and Cursor (or Codex and Grok Build) for a prediction-market or crypto bot project, who care more about not leaking keys than about benchmark scores.

Not for: Benchmark shoot-outs or price comparisons. Plans and prices change often, so check each tool's pricing page.

How the four compare, checked and tested

On Oct 25, 2026 we re-checked every row of this comparison against each vendor's current docs. Then we ran what we could without a paid session. We installed Grok Build 1.0.70 and ran grok inspect on a test repo that held all four tools' config files. We ran Codex CLI 0.164.0's codex sandbox command against a fake key file. We ran the guard hook from the setup prompt against sample inputs in each tool's documented format. No AI model was called. The table below is the corrected version.

Claude Code Cursor Codex Grok Build
What it is Terminal-first agent; also IDE extensions and a desktop app AI code editor with Agent (plus CLI and cloud agents) OpenAI's coding agent: CLI, IDE extension, desktop app xAI's terminal agent (grok): TUI, headless grok -p, ACP for editors
Rules file CLAUDE.md; reads AGENTS.md when there's no CLAUDE.md (v2.1.277+) AGENTS.md or .cursor/rules/*.mdc (plain .md there is ignored) AGENTS.md AGENTS.md, CLAUDE.md, *.md in .grok/rules/, .claude/rules/, .cursor/rules/ (not .mdc)
Skills .claude/skills/ .cursor/skills/, .agents/skills/, also .claude/skills/ .agents/skills/ .grok/skills/, also .claude/skills/ and Cursor skill folders
Hooks that can block PreToolUse in settings.json; exit 2 blocks hooks.json (beforeShellExecution, beforeReadFile, preToolUse); exit 2 or "permission": "deny" blocks hooks.json or config.toml; PreToolUse; exit 2 blocks. New or changed hooks are skipped until you trust them in /hooks .grok/hooks/*.json; also loads hooks from .claude/settings.json. Version 1.0.70 refused our .cursor/hooks.json hook. Project hooks need /hooks-trust
Broken or slow hook Fails open unless "onFailure": "block" (v2.1.295+) Fails open unless "failClosed": true; invalid JSON output blocks Errors, timeouts and bad output can fail without blocking. No switch Timeouts, crashes and bad output fail open (default timeout 5 s). No switch
Block secret files permissions.deny (Read(**/.env)) for the Read tool; sandbox.filesystem.denyRead for Bash .cursorignore (doesn't cover terminal or MCP tools); readBoundary: "workspace" A permission profile with the key folder set to "none" [permission] deny rules; a custom sandbox profile with a kernel deny list. It also loads Claude's permissions.deny
Reads outside the project The Read tool asks first. Sandboxed Bash can read most of the machine unless you add denyRead Allowed without asking by default (Read Access = System) Allowed: we read a key file one folder up Allowed under the workspace profile; only strict limits reads
Sandbox default Off; /sandbox turns it on. If bubblewrap is missing it runs unsandboxed unless failIfUnavailable: true Approval prompts by default; Run Modes add a sandbox (Landlock on Linux 6.2+, Seatbelt on macOS) with network off On: writes limited to the workspace, network off, .git read-only Off; --sandbox workspace, read-only, strict or a custom profile
"Run everything" mode bypassPermissions Run Everything (no sandbox) --yolo (no sandbox, no approvals) --always-approve; deny rules and hooks still apply

Which to pick for a trading bot:

  • Safest defaults with the least setup: Codex. Network is off and writes stay in the workspace. It can still read your key files, so add the permission profile below.
  • Most control in a terminal: Claude Code. Deny rules, many hook events and a fail-closed switch for hooks. Turn on /sandbox with failIfUnavailable. Our hooks recipe is a ready-made guard.
  • An editor: Cursor. Use a sandboxed Run Mode, set Read Access to Workspace, and add a beforeShellExecution hook with failClosed: true. .cursorignore alone doesn't stop the terminal.
  • Already on Grok: Grok Build. It reuses your AGENTS.md, Claude skills, Claude hooks and Claude deny rules once you trust the folder. Its hooks can't fail closed, so use a custom sandbox profile and keep --always-approve off.

What we found:

  • AGENTS.md is now the one rules file all four read. Claude Code added it in v2.1.277. If a CLAUDE.md exists, Claude reads only that, so import @AGENTS.md from it. A Cursor-style .mdc rule doesn't travel. grok inspect loaded our .cursor/rules/plain.md and skipped bot-safety.mdc, and Cursor itself ignores plain .md in that folder. The old prompt told Cursor users to write the .mdc, which Grok Build silently drops.
  • Grok Build didn't load the Cursor hook. The old table said it did. Version 1.0.70 reported: this Cursor hook won't run until Grok reads Cursor hook replies. It did load the hook and all 3 deny rules from .claude/settings.json.
  • Grok Build loaded nothing until the folder was trusted. Without trust, grok inspect listed no instructions, no skills, no hooks and no permissions. After --trust it found all of them. Your guardrails are gated by the same switch that protects you from a stranger's repo.
  • Only two of the four can fail closed. Claude Code (onFailure: "block") and Cursor (failClosed: true) can block when the hook crashes or times out. Codex and Grok Build can't. The guard below exits 2 on its own errors (tested), but that doesn't help if the hook process is killed or times out.
  • "Keep keys outside the project" isn't enough on its own. The old step 2 said it "covers the gaps in every tool". It doesn't. Codex's default sandbox printed our fake key from one folder up. Cursor reads outside the workspace without asking unless you switch Read Access to Workspace. Grok's workspace profile reads everywhere. Each tool needs its own deny setting, below.
  • The pattern hook is a tripwire, not a wall. All 42 sample cases passed. Then we tried six rewrites a model could plausibly produce, and five got through: git -C . push, a Python one-liner opening .env, cat .e""nv, env, and --mode live. The sandbox and the bot's own code limits do the real blocking.
  • Stale lines fixed: .cursorignore no longer lists Inline Edit. Codex's untrusted approval policy is retired. Claude Code's sandbox quietly falls back to no sandbox when a dependency is missing.

Codex sandbox on Oct 25, 2026 (codex-cli 0.164.0, Linux, fake key):

$ codex sandbox -- cat ../fakekeys/kalshi.pem
FAKE-KEY-123
$ codex sandbox -- sh -c 'echo x > ../fakekeys/written'
sh: 1: cannot create ../fakekeys/written: Read-only file system
$ codex sandbox -- sh -c 'echo x >> .git/config'
sh: 1: cannot create .git/config: Read-only file system
$ codex sandbox -- curl -s -m 8 -o /dev/null -w '%{http_code}' \
    https://api.elections.kalshi.com/trade-api/v2/exchange/status
000
# after adding the profile below to config.toml:
$ codex sandbox -- cat ../fakekeys/kalshi.pem
cat: ../fakekeys/kalshi.pem: Permission denied
# ~/.codex/config.toml (use your real key folder path)
default_permissions = "bot"

[permissions.bot]
extends = ":workspace"

[permissions.bot.filesystem]
"/home/you/.config/kalshi" = "none"

The deny setting per tool for a key in ~/.config/kalshi/:

  • Claude Code: add Read(~/.config/kalshi/**) to permissions.deny for the Read tool. With /sandbox on, add "~/.config/kalshi" to sandbox.filesystem.denyRead so cat is blocked too. Set failIfUnavailable: true.
  • Cursor: set Read Access to Workspace, or put "readBoundary": "workspace" in .cursor/sandbox.json (Cursor 3.23+).
  • Codex: use the permission profile above.
  • Grok Build: in ~/.grok/sandbox.toml add a profile with extends = "workspace", restrict_network = true and deny = ["/home/you/.config/kalshi", "**/.env", "**/*.pem"]. Run with --sandbox and that profile name. On Linux, read-deny needs bubblewrap.

Guard hook test output (trimmed to the summary lines):

$ python -m pytest -q tests/test_guard.py
..........................................                       [100%]
42 passed in 0.72s
# 7 bad + 6 safe commands x 3 input shapes, 2 secret reads, 1 garbage

The hook script and test file are the ones the prompt below asks for. Your agent will write its own, so run its tests yourself and try a rewrite or two.

Follow-up prompt for after the setup prompt has run:

Show me, by running commands, what your guardrails actually block.
1. Run your guard test file and paste the summary line.
2. Feed the hook these and report allow or block for each:
   git -C . push; cat .e""nv; python bot.py --mode live
3. Try to read my key folder with a shell command (cat, head) and
   with your file-read tool. Paste the exact errors.
4. Say which of my settings would let any of these through, and
   what to change. Don't change anything yourself.

We're not affiliated with any of these tools. Plans and prices change often; check Claude, Cursor, Codex and xAI before you buy.

What prompt do you paste into your AI coding tool?

Works in Claude Code, Cursor, Codex/ChatGPT, Grok or any agent that can write files. Paste it into an empty folder. Read what it builds before you run anything.

I'm about to build a Kalshi / Polymarket US bot with you. Before writing
any bot code, set up guardrails for THIS tool, using only its official
docs (Claude Code: code.claude.com/docs, Cursor: cursor.com/docs, Codex:
developers.openai.com/codex, Grok Build: docs.x.ai/build). Fetch the
pages; don't rely on memory. If a feature isn't documented for this
tool, say so instead of inventing config.

1. Write the rules in AGENTS.md (all four tools read it; if CLAUDE.md
   exists, add @AGENTS.md to it): paper/demo mode by default; live needs
   --live AND a typed confirmation; hard limits enforced in code; never
   read, print or commit .env, *.pem, *.key; never run the bot live
   yourself; never git push without asking.
2. My keys live in ~/.config/kalshi/. Block reads of that folder and of
   .env / *.pem with this tool's documented mechanisms: deny rules, a
   sandbox deny list or permission profile, read boundary. Cover BOTH
   your file-read tool and shell commands like cat. List what is still
   not covered.
3. Add one blocking hook (PreToolUse / beforeShellExecution) that stops
   commands containing --live, git push, or .env / *.pem paths. It must
   exit 2 on its own errors. Tell me whether this tool can also block
   when the hook crashes or times out, and set that if it can.
4. Tell me how to turn on this tool's sandbox and its exact defaults
   for reads, writes and network.
5. Write tests/test_guard.py that feeds sample hook inputs in this
   tool's documented JSON format, run it, and paste the result.
Then summarize what's protected and what's still up to me.

How do you build it, step by step?

  1. Pick your tool from the table: terminal or editor, and how much setup you want.
  2. Keep keys outside the project, then deny that folder. Put your Kalshi demo key in something like ~/.config/kalshi/demo.pem and reference it by path in an env var. That keeps it out of git, but three of the four tools can still read it by default, so add the per-tool deny setting above.
  3. Paste the prompt into the tool you picked, inside your empty bot folder.
  4. Read what it created. Check the rules file, the hook script and the deny rules or ignore file against the official docs linked below.
  5. Turn on the sandbox if it's off: /sandbox plus failIfUnavailable: true in Claude Code, a sandboxed Run Mode in Cursor, your custom profile in Grok Build. Codex's is on by default; leave it there. In Grok Build, run grok inspect to confirm your rules, hooks and deny rules loaded.
  6. Test the guard: run the follow-up prompt above. Ask it to "run the bot live" and "print the .env file". Both should be stopped by the hook or sandbox, not just by the model being polite. Expect some rewrites to slip past the hook; ours let 5 of 6 through.
  7. Add the Safety Pack files, then start a bot recipe, such as the Kalshi AI trading bot.

How do you test it in paper or demo mode first?

Your choice of AI tool doesn't change the trading setup: every BotCookery bot runs on Kalshi demo or a local paper ledger first, whichever tool wrote it. The guardrails above add one rule on top: the agent never starts live mode. You do, in your own terminal, after days of clean paper logs.

If you switch tools later, the bot doesn't care. Code, limits and paper logs are plain files. AGENTS.md and skill folders carry over. Sandbox and deny settings don't, so redo step 2 in the new tool.

What safety checks does it need before real money?

Tick every box before the bot touches real money. The full rules file, .gitignore and pre-commit hook are in the Safety Pack.

Which official docs did we check?

Endpoints and rules were checked against these pages on Oct 25, 2026. APIs change, so if something here disagrees with the official docs, trust the docs and tell us.

Frequently asked questions

Is Claude Code better than Cursor for trading bots?

Neither writes better trading strategies. Claude Code gives you finer control in the terminal (deny rules, many hook events, an optional sandbox). Cursor suits people who want to review every change in an editor, and it supports rules, skills and hooks too. Pick the one whose guardrails you'll actually set up.

What's the main difference between Claude Code and Cursor?

Claude Code is an agent you run mainly in a terminal (with IDE extensions and a desktop app). Cursor is a full code editor with an AI agent inside it. Their config also differs: CLAUDE.md and .claude/settings.json versus .cursor/rules/ and .cursor/hooks.json. Cursor can load Claude Code hooks and skills.

Which AI coding tool is safest for code that handles API keys?

By default, Codex: its sandbox limits writes to the workspace and keeps network off. It still read a key file outside the project in our test until we added a permission profile. Claude Code, Cursor and Grok Build can be locked down as tightly, but you turn it on.

Does .cursorignore protect my .env file?

Partly. Cursor's docs say .cursorignore blocks Agent, Tab and @-mention access, but terminal and MCP tools used by the agent can't be blocked by it. Use a sandboxed Run Mode, set Read Access to Workspace, and add a beforeShellExecution hook with failClosed: true.

Can I use the same safety setup across all four tools?

Partly. AGENTS.md is read by all four, and skill folders are widely shared. Cursor and Grok Build load Claude Code hooks; Grok Build also loads Claude's deny rules. Codex hooks use a similar format. Sandbox, read-boundary and fail-closed settings are tool-specific.

Which one should a beginner pick?

Whichever you already pay for. Then follow the setup prompt above so the guardrails are on before the first line of bot code.

More from the kitchen: Recipes by platform · Kalshi & Polymarket fee calculator · How we verify recipes · Safety Pack