Sandboxed Bash Setup For Autonomous Coding Agents
Enable Claude Code bash sandboxing for autonomous agents: filesystem and network boundaries, auto-allow rules, dependency checks, and fail-closed settings.
Open the source and read safety notes before installing.
Safety notes
- Sandboxing reduces blast radius but does not eliminate malicious code—review diffs and keep branch protection enabled.
- Missing sandbox dependencies previously caused silent disable; use fail-closed settings and verify `/sandbox` status after upgrades.
- autoAllowBashIfSandboxed auto-approves some commands—pair with deny rules for destructive patterns.
Privacy notes
- Sandboxed commands still read repository files within allowed paths; do not store secrets in sandbox-writable directories.
- Network-allowed domains determine where agent output or tokens might be sent—document allowed egress.
- Sandbox logs and permission prompts may capture command text including paths and environment variable names.
Prerequisites
- Claude Code on macOS, Linux, or WSL with sandbox dependencies available or installable.
- Permission to edit project or managed settings.json sandbox blocks.
- Representative build and test commands your agents run in CI.
- A rollback plan if sandbox misconfiguration blocks legitimate workflows.
Schema details
- Install type
- copy
- Reading time
- 8 min
- Difficulty score
- 60
- Troubleshooting
- Yes
- Breaking changes
- No
- Scope
- Source repo
Full copyable content
Turn on bash sandboxing in settings, verify `/sandbox` dependency status, constrain network and write paths, and pair `autoAllowBashIfSandboxed` with explicit deny rules for autonomous sessions.About this resource
TL;DR
Autonomous Claude Code sessions run many shell commands. Enable bash sandboxing to
limit filesystem writes and network egress, verify dependencies with /sandbox,
use sandbox.failIfUnavailable when you prefer errors over silent disable, and
only enable autoAllowBashIfSandboxed alongside explicit deny rules for
destructive commands.
Prerequisites & Requirements
- {"task": "Platform supported", "description": "macOS, Linux, or WSL with sandbox prerequisites documented for your OS"}
- {"task": "Command inventory", "description": "Build, test, and package commands agents need are listed"}
- {"task": "Settings access", "description": "Project or managed settings can define sandbox blocks"}
- {"task": "Pilot session", "description": "A disposable repo can test blocked and allowed commands"}
- {"task": "Deny rules drafted", "description": "Destructive shell patterns have permissions.deny coverage"}
Core Concepts Explained
Sandbox constrains Bash side effects
Sandbox settings limit which paths Bash may write and which network destinations commands may reach. This matters most when auto mode or background agents run shell without per-command human approval.
Dependencies must be present
Claude Code exposes /sandbox to show dependency status. Missing bubblewrap,
socat, or platform-specific tools can prevent sandbox startup—treat warnings as
blocking in regulated environments.
autoAllowBashIfSandboxed trades friction for speed
When enabled, some sandboxed commands skip repeated approval prompts. That accelerates agents but requires deny rules so excluded or edge-case commands cannot bypass ask permissions.
Worktrees change write scope
Release notes document sandbox write allowlists in git worktrees covering shared
.git paths—test agents both in the main checkout and linked worktrees.
Step-by-Step Implementation Guide
Audit agent shell usage. List commands your autonomous workflows run: package installs, test runners, linters, and deploy scripts.
Enable sandbox in settings. Set
sandbox.enabledin project settings and open/sandboxto confirm dependencies install cleanly on each OS you support.Configure filesystem rules. Allow writes only to the workspace and temp directories agents need; deny system paths and credential stores.
Configure network rules. Use
sandbox.network.allowedDomainsfor required registries and APIs; adddeniedDomainsfor sensitive destinations even when wildcards are broad.Set fail-closed behavior. Use
sandbox.failIfUnavailablein managed settings when silent unsandboxed fallback is unacceptable.Enable auto-allow cautiously. Turn on
autoAllowBashIfSandboxedonly after deny rules coverrm, credential reads, and outbound bulk uploads.Test in worktrees. If agents use
EnterWorktreeor--worktree, verify write allowlists and network rules in linked checkouts.Document operator playbook. Tell on-call engineers how to read
/sandboxoutput and temporarily widen rules through reviewed settings changes.
Verification Checklist
- {"task": "/sandbox green", "description": "Dependencies show installed on pilot machines"}
- {"task": "Blocked command test", "description": "A disallowed write or network call fails visibly"}
- {"task": "Allowed pipeline test", "description": "Standard build and test commands succeed sandboxed"}
- {"task": "Fail-closed verified", "description": "Missing deps error instead of silent disable when configured"}
- {"task": "Deny rules active", "description": "Destructive patterns still blocked with auto-allow enabled"}
Troubleshooting
Sandbox silently disabled
Upgrade to a build with the startup warning fix and enable
sandbox.failIfUnavailable so sessions error when deps are missing.
Go or Terraform TLS failures behind proxy
On macOS, evaluate sandbox.enableWeakerNetworkIsolation only after security
review when MITM proxies break certificate verification.
Commands with $VAR expansions blocked
Release notes fixed auto-allow behavior for shell expansions—upgrade Claude Code before blaming sandbox rules.
Linux paths need bubblewrap overrides
Use managed sandbox.bwrapPath and sandbox.socatPath when standard packages
install to non-default locations.
Source Verification Notes
Verified against the public anthropics/claude-code repository README and
CHANGELOG.md on 2026-06-13:
CHANGELOG.mddocuments/sandboxUI for dependency status and settings tabs for permissions alongside sandbox configuration.CHANGELOG.mdaddssandbox.failIfUnavailableto error when sandbox is enabled but cannot start instead of running unsandboxed silently.CHANGELOG.mdrecords fixes forautoAllowBashIfSandboxedwith shell expansions and security fixes when excluded commands bypassed ask rules.CHANGELOG.mddocumentssandbox.network.deniedDomains, managedsandbox.bwrapPath/sandbox.socatPath, and worktree write allowlist fixes.- The root README directs integration feedback to GitHub issues at
anthropics/claude-code.
Duplicate Check
This guide complements sandbox-environments-for-claude-code-risk-boundaries.mdx and secure deployment guides. Those entries cover broader risk boundaries and host deployment. This guide focuses on bash sandbox settings for autonomous agent shell usage.
References
- Claude Code sandboxing - https://code.claude.com/docs/en/sandboxing
- Claude Code settings - https://code.claude.com/docs/en/settings
- Claude Code permissions - https://code.claude.com/docs/en/permissions
- Sandbox environments guide - sandbox-environments-for-claude-code-risk-boundaries
Source citations
Add this badge to your README
Show that Sandboxed Bash Setup For Autonomous Coding Agents is listed on HeyClaude. Paste this Markdown into your README — it renders the badge and links back to this page.
[](https://heyclau.de/entry/guides/sandboxed-bash-setup-for-autonomous-coding-agents)How it compares
Sandboxed Bash Setup For Autonomous Coding Agents side by side with 3 alternatives on trust, install, platform support, and disclosed safety notes — all from reviewed registry metadata.
| Field | Sandboxed Bash Setup For Autonomous Coding Agents Enable Claude Code bash sandboxing for autonomous agents: filesystem and network boundaries, auto-allow rules, dependency checks, and fail-closed settings. Open dossier | Auto Mode Hard-Deny Policies For Safe Automation Configure Claude Code auto mode hard-deny rules that block high-risk actions unconditionally, complement soft-deny prompts and team permission policy. Open dossier | Sandbox Environments For Claude Code Risk Boundaries Define sandbox environment boundaries for Claude Code: managed settings, network egress, filesystem scope, worktree isolation, and when to fail closed. Open dossier | Claude Code JetBrains Setup for Large Repositories Configure Claude Code in JetBrains IDEs for large repositories: terminal rendering fixes, synchronized output, sparse context, and plugin workflows for IntelliJ-based teams. Open dossier |
|---|---|---|---|---|
| Trust | ||||
| Install risk | Review first | Review first | Review first | Review first |
| Notes | Safety ✓ Privacy ✓ | Safety ✓ Privacy ✓ | Safety ✓ Privacy ✓ | Safety ✓ Privacy ✓ |
| Category | guides | guides | guides | guides |
| Source | source-backed | source-backed | source-backed | source-backed |
| Author | kiannidev | kiannidev | kiannidev | kiannidev |
| Added | 2026-06-13 | 2026-06-13 | 2026-06-13 | 2026-06-14 |
| Platforms | Claude Code | Claude Code | Claude Code | Claude Code |
| Source repo | — | — | — | — |
| Safety notes | ✓Sandboxing reduces blast radius but does not eliminate malicious code—review diffs and keep branch protection enabled. Missing sandbox dependencies previously caused silent disable; use fail-closed settings and verify `/sandbox` status after upgrades. autoAllowBashIfSandboxed auto-approves some commands—pair with deny rules for destructive patterns. | ✓Hard-deny rules block regardless of user intent or allow exceptions—misconfiguration can halt legitimate workflows. Auto mode classifiers can still fail open with evaluation errors; hard deny is not a substitute for branch protection and CI gates. Do not rely on auto mode alone for secrets handling; deny credential reads and outbound bulk transfers explicitly. | ✓Sandbox environments reduce accidental exfiltration and destructive writes but do not replace code review, secret scanning, or MCP tool governance. Managed allowManagedDomainsOnly and read-path restrictions require complete sandbox blocks—partial managed files can be ignored if sandbox keys are missing. Background sessions and auto mode can still trigger network permission prompts—align sandbox policy with auto mode hard-deny rules. | ✓Large-repo sessions amplify token usage—use sparse context and compaction hygiene to avoid runaway costs. JetBrains terminals on 2026.1+ use synchronized output; avoid custom ANSI themes that fight IDE rendering. Do not mount entire monorepo secrets into agent sessions; scope working directories per module. |
| Privacy notes | ✓Sandboxed commands still read repository files within allowed paths; do not store secrets in sandbox-writable directories. Network-allowed domains determine where agent output or tokens might be sent—document allowed egress. Sandbox logs and permission prompts may capture command text including paths and environment variable names. | ✓Auto mode classifiers evaluate tool names, arguments, and session context that may include file paths and repository metadata. Denial messages and debug logs can retain snippets of blocked commands; restrict log access on shared machines. Managed settings sync may expose rule text to all enrolled clients—avoid embedding internal codenames you do not want widely visible. | ✓Network allowlists define which third parties may receive tool output or package download metadata. Filesystem allowlists still expose repository contents to local processes—classify repos before widening read paths. Worktree isolation guards prevent shared-checkout edits but transcripts may still contain sensitive diffs—follow normal log retention policy. | ✓IDE-integrated sessions expose package names, module paths, and dependency graphs in prompts. Usage and session data follow the same data-usage policies as terminal Claude Code. Shared JetBrains licenses on VDI pools can leak session resumes—use per-developer config directories. |
| Prerequisites |
|
|
|
|
| Install | — | — | — | — |
| Config | — | — | — | — |
| Citations | ||||
| Claim | Unclaimed | Unclaimed | Unclaimed | Unclaimed |
Signals
Loading live community signals…
A short, calm digest of reviewed Claude resources. Unsubscribe any time.