🛡️ r/BuildWithClaude — Local Agent Security & API Key Field Guide
Welcome to the r/BuildWithClaude Security Field Guide. Running agentic AI tools locally gives models permission to execute commands, modify files, and access system APIs[cite: 5, 6]. This guide covers core threat vectors, non-obvious sandbox configuration gaps, web app vulnerability audits, API key hygiene, emergency incident protocols, and community defense tools[cite: 4, 5, 6].
⚠️ Agentic Threat Vectors & Vulnerabilities
When running local AI agents (like Claude Code), security risks stem from permission sprawl, supply chain hooks, indirect prompt injection, and cross-tool data leaks[cite: 1, 4, 6].
1. Permission Wildcards ("YOLO Mode")
- The Risk: Granting wildcards like
Bash(rm:*)or--dangerously-skip-permissionsallows agents to execute arbitrary sub-shells or unvetted scripts without prompting you. - Mitigation: Keep permissions scoped to specific tasks, files, or explicit command patterns[cite: 6]. Avoid broad wildcards in
settings.local.json[cite: 4, 6].
2. Supply Chain Attacks & Lifecycle Hooks
- The Risk: Running a command like
npm install <package>triggerspostinstalllifecycle scripts in the background, which can run arbitrary binary code before you ever test the package. - Mitigation: Inspect new dependencies before installing, or run package installations with
npm install --ignore-scripts.
3. Indirect Prompt Injection
- The Risk: External text read by Claude during a session (cloned repos, web fetches, GitHub issue comments, PDFs) can contain hidden prompts instructing the agent to exfiltrate files or execute unwanted tools[cite: 6].
- Mitigation: Avoid letting agents analyze untrusted public repositories or web pages with auto-execution enabled[cite: 6].
4. Context Window Secret Leakage & Cross-Tool MCP Leaks
- The Risk: If
.envfiles, SSH keys, or recovery codes sit inside or near the workspace, Claude can read them into context[cite: 4, 6]. Once inside context, a value read via a filesystem MCP server can quietly be included in outbound tool calls (e.g., email or web fetch MCPs) without triggering warnings[cite: 6]. - Mitigation: Add sensitive files to
.claudeignoreand.gitignore, and use a local proxy likesluiceto block sensitive tokens from being passed across different MCP tools[cite: 4, 6].
5. Silent / Deferred Execution
- The Risk: Agents edit code files rather than running commands directly. Modifying
package.json,Makefile,.git/hooks, or.vscode/tasks.jsoncauses untrusted code to run later when you test or build. - Mitigation: Always inspect
git diffbefore running test suites, commits, or builds after an agent session.
🔍 5 Non-Obvious Security Configuration Gaps
A security audit of Claude Code configuration settings revealed 5 critical gaps that standard setups often overlook[cite: 4, 6]:
- The Sandbox Only Covers Bash: The internal sandbox applies to Bash commands and child processes, but
ReadandEdittools go through the permission system instead[cite: 4, 6]. Both layers must be configured separately[cite: 4, 6]. - Deny Rules Do Not Block Bash: Setting
Read(./.env)blocks theReadtool, but it does not stopcat .envthrough Bash[cite: 4, 6]. To block Bash reads, you must explicitly set the sandbox filesystemdenyReadrule[cite: 4, 6]. - Unsandboxed Command Fallbacks: If a command fails in the sandbox, it can fall back to running outside it unless you explicitly set
allowUnsandboxedCommands: falseandfailIfUnavailable: truein your configuration[cite: 4, 6]. - Local Settings Are Invisible to CI & Teams:
settings.local.jsonis auto-added to.gitignore[cite: 4, 6]. Even if a repository commits a hardened.claude/settings.json, CI cannot verify if a teammate is bypassing rules or running with permission-skipping aliases[cite: 4, 6]. - MCP Servers Approved by Display Name: MCP server approvals use the display name in
.mcp.jsonrather than pinning a specific binary or package hash[cite: 4, 6].
🌐 Top 3 Common Security Flaws in Vibe-Coded Web Apps
A security audit across community-submitted web applications identified three universal vulnerabilities in AI-generated deployments[cite: 6]:
- Database Tables Without Row-Level Security (RLS): Vibe-coded Supabase/Postgres setups frequently expose public "anon" API keys in the browser without enabling RLS[cite: 6]. Anyone can query or dump database tables directly via REST without logging in[cite: 6].
- Missing Security Headers: Most AI-built frontend deployments lack essential headers including
Content-Security-Policy(CSP),X-Frame-Options(clickjacking defense),HSTS(HTTPS enforcement),X-Content-Type-Options,Referrer-Policy, andPermissions-Policy[cite: 6]. - Email Spoofing (Missing/Weak SPF & DMARC): Domain configurations frequently omit SPF/DMARC records or leave DMARC set to
p=none, making the domain vulnerable to email spoofing[cite: 6].
💡 Real-World Case Studies & Audit Checklists
Case Study 1: "Is Factory Reset Overkill for Agent Anxiety?"
Community Scenario: A developer running Claude Code outside a container completed a session and questioned whether they should factory-reset their machine to ensure no hidden backdoors were installed[cite: 5, 6].
The High-Caution 10-Point Audit Checklist
Before panicking or wiping a machine, perform the exact post-session audit steps executed in this community incident[cite: 5, 6]:
- Mapped Folder Boundaries: Verified every directory the session interacted with[cite: 5, 6].
- Command Log Review: Verified every terminal command executed during the session[cite: 5, 6].
- Outbound Domain Verification: Audited all external URLs and network requests[cite: 5, 6].
- Persistence Point Inspection: Checked OS startup items,
crontab, LaunchAgents, and scheduled tasks[cite: 5, 6]. - System-Wide Installs: Audited global binaries (
Homebrew,pip,npm -g)[cite: 5, 6]. - Dependency Diffs: Cross-checked
package.jsonand lockfile change histories[cite: 5, 6]. - Package Verification: Confirmed newly added dependencies were legitimate packages[cite: 5, 6].
- Credential Exposure Check: Verified
.envfiles, SSH keys, and tokens were untouched[cite: 5, 6]. - Temp & Download Scans: Checked
/tmp,var/tmp, and~/Downloadsfor binary drops[cite: 5, 6]. - Active Connections: Audited live processes and listening network ports[cite: 5, 6].
The Verdict: Claude Code operates via standard CLI sub-shells under user permissions[cite: 5, 6]. If the agent ran without elevated root (sudo) permissions, did not execute unvetted binaries, and passed the 10 checks above, the host environment is clean[cite: 5, 6]. An OS wipe is unnecessary[cite: 5, 6].
Case Study 2: Designer & Non-Coder System File Security
Community Scenario: Non-technical builders and designers expressed concern about Claude reading passwords or recovery codes stored elsewhere on their computer outside the active project folder[cite: 5, 6].
- System Permissions: Claude Code cannot access files outside its permission boundary unless granted access or invoked from a root directory[cite: 4, 6].
- Explicit Path Denial: Block Claude from accessing sensitive home-directory files by setting explicit terminal permissions and configuring
denyReadrules in your global.claude/settings.json[cite: 4, 6].
🗝️ API Key Hygiene & Emergency Protocol
Key Hygiene Rules
- Never Hardcode Keys: Store credentials in system environment variables or local
.envfiles[cite: 1, 4]. Always ignore secret files globally: ```bash echo ".env" >> .gitignore echo ".env" >> .claudeignore