Skip to main content
guidesSource-backedReview first Safety Privacy

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.

by kiannidev·added 2026-06-13·
HarnessClaude Code
Review first review before installing

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
Source repository stats
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

  1. Audit agent shell usage. List commands your autonomous workflows run: package installs, test runners, linters, and deploy scripts.

  2. Enable sandbox in settings. Set sandbox.enabled in project settings and open /sandbox to confirm dependencies install cleanly on each OS you support.

  3. Configure filesystem rules. Allow writes only to the workspace and temp directories agents need; deny system paths and credential stores.

  4. Configure network rules. Use sandbox.network.allowedDomains for required registries and APIs; add deniedDomains for sensitive destinations even when wildcards are broad.

  5. Set fail-closed behavior. Use sandbox.failIfUnavailable in managed settings when silent unsandboxed fallback is unacceptable.

  6. Enable auto-allow cautiously. Turn on autoAllowBashIfSandboxed only after deny rules cover rm, credential reads, and outbound bulk uploads.

  7. Test in worktrees. If agents use EnterWorktree or --worktree, verify write allowlists and network rules in linked checkouts.

  8. Document operator playbook. Tell on-call engineers how to read /sandbox output 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.md documents /sandbox UI for dependency status and settings tabs for permissions alongside sandbox configuration.
  • CHANGELOG.md adds sandbox.failIfUnavailable to error when sandbox is enabled but cannot start instead of running unsandboxed silently.
  • CHANGELOG.md records fixes for autoAllowBashIfSandboxed with shell expansions and security fixes when excluded commands bypassed ask rules.
  • CHANGELOG.md documents sandbox.network.deniedDomains, managed sandbox.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

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.

Listed on HeyClaude
[![Listed on HeyClaude](https://heyclau.de/badge/guides/sandboxed-bash-setup-for-autonomous-coding-agents.svg)](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.

FieldSandboxed 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 riskReview firstReview firstReview firstReview first
Notes Safety Privacy Safety Privacy Safety Privacy Safety Privacy
Categoryguidesguidesguidesguides
Sourcesource-backedsource-backedsource-backedsource-backed
Authorkiannidevkiannidevkiannidevkiannidev
Added2026-06-132026-06-132026-06-132026-06-14
Platforms
Claude Code
Claude Code
Claude Code
Claude Code
Source repo
Safety notesSandboxing 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 notesSandboxed 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
  • 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.
  • Claude Code with auto mode available on your provider and organization policy.
  • Permission to edit project or managed settings.json for the target repositories.
  • A list of actions that must never run without explicit human approval.
  • Pilot engineers who can trigger both allowed and blocked auto mode actions safely.
  • A team risk model separating read-only exploration from write-capable automation.
  • Managed settings distribution for Claude Code across developer machines.
  • Documented data classification for repositories and external APIs agents may call.
  • Platform coverage plan for macOS, Linux, and WSL sandbox dependencies.
  • JetBrains IDE 2025.2+ or 2026.1+ with the Claude Code plugin approved.
  • A large repository with documented sparse-context or monorepo CLAUDE.md hierarchy.
  • Sufficient heap for indexing; pilot on a representative module before org-wide rollout.
  • Team policy for MCP servers and permissions synced to IDE sessions.
Install
Config
Citations
ClaimUnclaimedUnclaimedUnclaimedUnclaimed

Signals

Loading live community signals…

More like this, weekly

A short, calm digest of reviewed Claude resources. Unsubscribe any time.