Skip to content

Claude Code Security: Sandboxing, Hooks & Team Guardrails

Claude Code security requires scoped settings.json deny rules, sandboxing, hooks, and vetted MCPs. Lock down your team setup and scan free.

Mark KashefClaude Code6 min read
Editorial ink illustration of Claude Code security showing a developer laptop wired to a padlocked sandbox lockbox

Claude Code security is the configuration of workspace deny rules, filesystem sandboxing, deterministic PreToolUse hooks, vetted MCP servers, and pre-merge scanning that lets engineers ship fast without exposing secrets or production infrastructure. Treat Claude Code like a capable junior engineer with terminal access: give it clear lanes, not root keys.

TL;DR

  • Anthropic's official Claude Code security docs center on defense in depth: permission allowlists, OS-level sandboxing, and never trusting uninspected repository instructions (CLAUDE.md, hooks, or .mcp.json).
  • Five concrete controls close most real team risk: .claude/settings.json deny rules on .env and ~/.ssh, sandboxed execution, PreToolUse safety hooks, approved MCP registries, and pre-launch outside-in scans.
  • Never run --dangerously-skip-permissions on a developer laptop that holds browser cookies, cloud CLI logins, or production credentials.
  • You can scan shipped Claude Code web apps, websites, skills, and GitHub repos for free at Lockpick and paste the generated remediation prompt right back into your session.

What Are the Five Claude Code Security Controls Every Team Needs?

Lock down Claude Code security at the settings, hook, and container layers before rolling seats out across your engineering org. Relying on engineers to remember to click "deny" on the forty-fifth permission prompt of the afternoon fails every single time.

Five Claude Code security controls covering settings.json rules, sandboxing, PreToolUse hooks, vetted MCPs, and Lockpick
Enforce permissions in settings.json, hooks, and sandboxes rather than relying on verbal habits.
  1. Team-managed .claude/settings.json deny rules: Commit baseline permission rules that explicitly deny reads of .env*, ~/.ssh/**, and cloud credential folders while allowing safe read and test commands so engineers avoid approval fatigue.
  2. OS or container sandboxing: Turn on Claude Code's sandbox boundaries so file writes stay inside the repo and unexpected outbound network requests get blocked by default.
  3. Deterministic PreToolUse hooks: Wire lightweight hook scripts that reject git push --force, destructive rm -rf targets, or piped curl uploads before the shell ever executes them.
  4. Vetted skills and MCP allowlists: Community skills and local MCP servers inherit local privileges. Review every .mcp.json against the Model Context Protocol security specification and our AI agent security checklist before approving it.
  5. Outside-in pre-merge scanning: Coding fast still leaves classic app flaws like exposed NEXT_PUBLIC_ keys or missing database Row-Level Security. Scan your app, skills, and GitHub repo free on Lockpick and verify against our vibe coding security guide.

How Should You Match Claude Code Permissions to Repo Risk?

Use strict read-only inspection on unfamiliar repositories, scoped team allowlists on daily product repos, and disposable containers for any autonomous headless run. One flat permission profile across every repo either slows senior engineers to a crawl or hands untrusted code full shell access.

Claude Code security permission matrix comparing untrusted repos, daily team engineering, and headless CI runs
Match Claude Code's permission posture to the sensitivity of the repository and credentials on the machine.
EnvironmentRecommended ModeMandatory GuardrailsHard Line (Never Allow)
Untrusted or External RepoPlan / read-only firstRead CLAUDE.md, .claude/hooks, and .mcp.json manually before granting workspace trustAutomatic shell commands or MCP startup
Daily Team EngineeringScoped allowlistShared settings.json deny rules on .env, sandbox enabled, approved MCP registryDirect pushes to main or production DB credentials
Headless CI / Batch AgentIsolated Docker containerEphemeral container, read-mostly scoped token, hard API spend cap, PR human reviewMounting host home directory or ~/.ssh

Keep API keys scoped per project with hard monthly caps too, as the developer losses in our OpenCode breach breakdown proved. And review the OWASP Top Ten whenever an agent touches authentication or payment routes.

How Do You Run a Practical Claude Code Security Review Before Shipping?

Combine an automated outside-in check with a five-minute human diff pass focused exclusively on boundaries: auth middleware, database policies, environment variables, and new dependencies. Asking Claude Code to review its own diff catches syntax bugs and obvious leaks, but it cannot see what your deployed server actually exposes to the internet.

That is why we run live deployments, agent skills, and GitHub repos through Lockpick before sharing a URL with users. Lockpick checks headers, exposed keys, open tables, email DNS, and skill files from the outside, then hands you a fix prompt ready for Claude Code to execute. For customer-facing systems that handle sensitive data, back that up with a human-verified AI cybersecurity review or compare scopes in our AI security audit breakdown. And if your org wants consistent standards across every developer seat, explore our AI training for teams workshops on Claude Code, hooks, and sandboxing.

Mark's Final Thoughts

Claude Code changes how fast a small engineering team can ship, and securing it does not mean turning off everything that makes it useful. Put deny rules in settings.json, keep sandboxing on, vet your skills and MCPs, and run a free Lockpick check before merging to production. Good guardrails let your engineers move faster with confidence instead of worrying about what ran in the terminal.

Claude Code Security FAQs

Is Claude Code safe to use on company repositories?

Yes, when configured with enterprise or team workspaces (training off), explicit deny rules for secret files in .claude/settings.json, sandboxing enabled, and an allowlist of approved MCP servers. Running Claude Code with unrestricted permissions on a laptop holding production credentials is where teams get burned.

What are the biggest Claude Code security risks for engineering teams?

The top risks are prompt injection hidden inside untrusted repositories or issues, unvetted community skills and MCP servers reading local .env or ~/.ssh files, accidental force pushes or destructive shell commands, and shipping AI-written app code with exposed client keys or missing database permissions.

How do PreToolUse hooks improve Claude Code security?

PreToolUse hooks run deterministic scripts before Claude Code executes a shell command or file edit. You can use them to block dangerous git force pushes, stop reads of secret files, or prevent raw curl calls that could exfiltrate local environment variables even if a prompt injection hits.

Should engineers ever use --dangerously-skip-permissions?

Only inside an isolated, disposable container with no production secrets, no host filesystem mount, and restricted outbound network access. Never run --dangerously-skip-permissions on a primary work laptop where browser sessions, cloud CLI tokens, or SSH keys live.

How can I run a Claude Code security review on my shipped app and skills?

Use Lockpick (lockpick.app) for a free outside-in scan of your live web app, website, agent skills, or GitHub repository. It checks exposed keys, open database endpoints, missing headers, and repo risks, then gives you a one-click fix prompt you can paste straight back into Claude Code.