Skip to main content

Sandbox & Safety

How Claude Code handles destructive operations, sandboxing, and enterprise controls.

Tool Safety Classification

Every tool self-reports its safety characteristics:

interface Tool {
isReadOnly(input): boolean // No side effects
isDestructive(input): boolean // Potentially harmful
isConcurrencySafe(input): boolean // Safe to run in parallel
}
ClassificationMeaningExamples
Read-onlyNo side effectsRead, Glob, Grep, WebSearch
Non-destructive writeCreates/modifies but recoverableFileEdit, FileWrite
DestructiveHard to reverseBash(rm ...), Bash(git reset --hard)

OS-Level Sandboxing

Claude Code supports operating system sandboxing for the Bash tool:

macOS — Seatbelt

Uses macOS sandbox profiles (sandbox-exec) to restrict file system access, network access, and process spawning for shell commands.

Linux — Landlock / Bubblewrap

Uses Linux security modules to create restricted execution environments for shell commands.

Sandbox Scope

  • File system access limited to project directory and temp files
  • Network access controlled by policy
  • Process spawning limited
  • System modification blocked

Enterprise Controls

Organizations can enforce policies that restrict Claude Code behavior:

Policy Limits

PolicyWhat It Controls
Token limitsMax tokens per session/request
Tool restrictionsWhich tools are available
Model restrictionsWhich models can be used
MCP restrictionsWhich MCP servers are allowed
File restrictionsWhich paths can be read/written
Command restrictionsWhich shell commands are permitted

Policy Sources

Enterprise policies are loaded from managed configuration and cannot be overridden by users:

🏢
Org Admin
📋
Managed Policy Config
⚙️
Claude Code
🔒
Enforce at every tool call

Policy always wins over user settings.

MDM Integration (macOS)

On macOS, policies can be distributed via Mobile Device Management (MDM), allowing organizations to configure Claude Code fleet-wide.

Destructive Operation Guards

Beyond permissions, Claude Code has built-in guards for dangerous operations:

File Operations

  • FileEdit requires reading the file first (ensures awareness of current content)
  • FileWrite warns when overwriting an existing file that hasn't been read
  • No tool can write to paths outside the project without explicit permission

Git Operations

  • Force push to main/master triggers a warning
  • git reset --hard flagged as destructive
  • Amending published commits flagged
  • Hook bypass (--no-verify) flagged

Shell Commands

  • Commands matching destructive patterns are flagged
  • Background commands have restricted tool access
  • Timeout enforcement prevents runaway processes

Anti-Distillation

Claude Code includes mechanisms to prevent its outputs from being used to train competing models — intellectual property protection at the API and output level.

Two Protection Layers
Fake Tool Injection (API-side)
Streamlined Output (client-side)

Fake Tool Injection

When enabled, the API request includes an anti_distillation: ['fake_tools'] parameter. The client sends this flag; the server-side behavior (presumably injecting decoy tool schemas) is not observable from the source alone.

🔧
ANTI_DISTILLATION_CC feature flag enabled?
💻
Entrypoint === 'cli' (not SDK)
🏢
shouldIncludeFirstPartyOnlyBetas()
☁️
GrowthBook: tengu_anti_distill_fake_tool_injection
🛡️
All pass → send anti_distillation: ['fake_tools']
src/services/api/claude.ts (line 301-313)
if (
feature('ANTI_DISTILLATION_CC')
? process.env.CLAUDE_CODE_ENTRYPOINT === 'cli' &&
shouldIncludeFirstPartyOnlyBetas() &&
getFeatureValue_CACHED_MAY_BE_STALE(
'tengu_anti_distill_fake_tool_injection', false)
: false
) {
result.anti_distillation = ['fake_tools']
}

Streamlined Output Mode

A separate "distillation-resistant" output format that reduces the information density of SDK outputs:

📨
Incoming message
Assistant (text)
Keep intact
Assistant (tool calls)
Collapse to category counts
Other messages
Drop entirely

Tool calls are collapsed into 5 category counts:

CategoryTools Included
searchesGrep, Glob, WebSearch, LSP
readsRead, ListMcpResources
writesWrite, Edit, NotebookEdit
commandsBash, PowerShell, Tmux, TaskStop
otherEverything else

Counts accumulate across consecutive tool-only messages and reset when text appears. Tool result messages pass through unchanged. Thinking content is omitted entirely.

Key Source Files

FilePurpose
src/utils/permissions/Permission and safety logic
src/services/policyLimits/Enterprise policy enforcement
src/tools/BashTool/Bash classifier and sandbox
src/services/api/claude.tsAnti-distillation fake_tools injection
src/utils/streamlinedTransform.tsDistillation-resistant output mode