Configure Claude Code Sandboxing in a Project Container
Use this guide to create a sandbox configuration repository for Claude Code and include it in a project container build.
For the full list of quickstarts, see Quickstart Guides.
In this quickstart, you will:
- Prerequisites - Verify you have what you need.
- Key Concepts - Understand the configuration files and how they work.
- Create a Sandbox Configuration Repository - Create a configuration repository with settings, hooks and skills.
- Include the Configuration in the Build - Clone the repository into the container during the build.
Prerequisites
Before starting, ensure that:
- You have completed Install Claude Code in a Project Container.
- You have a GitHub or GitLab account where you can create a public repository.
Key Concepts
settings.json
Configuration file that Claude reads on session start.
Settings follow a precedence hierarchy: managed (server/MDM/file) > CLI args > .claude/settings.local.json (gitignored) > .claude/settings.json (committed) > ~/.claude/settings.json (user level).
Arrays merge across scopes (concatenate and deduplicate). Scalars use the highest-priority scope. Deny always wins over allow at any level.
Sandbox Block
Block in settings.json that restricts what files and network endpoints Claude’s processes can access.
Uses bubblewrap for filesystem and network isolation and socat for proxied network access through domain allowlists.
In container environments, bubblewrap runs in a reduced capability mode (enableWeakerNestedSandbox) that retains filesystem, network and process isolation but cannot mount a fresh /proc.
Permissions Block
Block in settings.json that gates Claude’s tool calls, including Bash.
Rules are evaluated in order: deny > ask > allow, first match wins.
Bash patterns are glob-style and shell-operator-aware. Read/Edit patterns use gitignore-style globs.
Deny rules on Read and Edit only block Claude’s built-in file tools, not bash subprocesses.
For example, Read(./.env) blocks the Read tool but does not prevent cat .env.
Use sandbox denyRead rules to enforce OS-level file access restrictions.
Hooks Block
Block in settings.json that defines commands or scripts that run on agent lifecycle events.
Claude Code supports 26 hook events. Key events for containers include SessionStart, PreToolUse, PostToolUse, UserPromptSubmit, PermissionRequest and Stop.
Hooks can block execution, modify tool input (via updatedInput in the output JSON) and override permission decisions.
Matchers use regex syntax, not glob. See the full hooks reference.
Hook Scripts
Standalone bash scripts referenced in the hooks block in settings.json.
Easier to use for more complex logic or processes than the individual commands set in settings.json.
AI Workbench Skills Folder
A sub-directory of ~/.claude/skills/ containing a skill package for AI Workbench.
Has a SKILL.md file and a references/ folder with supporting documents about the project container and AI Workbench.
Claude loads skills automatically when the activation condition in the skill’s frontmatter is met.
Create a Sandbox Configuration Repository
Step One: Create a public repository with the following structure.
The repository will be cloned to ~/.claude/ inside the container.
Step Two: Create a settings.json file.
The settings file configures the model, process sandbox, permissions and hooks.
Protect it from agent modification by including it in the sandbox denyWrite list.
“model“ sets the default model for sessions in the container.
Users can override it per session.
“sandbox“ example block protects the agent’s own configuration and credentials from modification.
The denyWrite list covers everything that defines the agent’s constraints.
The denyRead list blocks access to authentication tokens.
autoAllowBashIfSandboxed is false so bash commands still require approval even with the sandbox active.
enableWeakerNestedSandbox activates the container-compatible sandbox mode.
Filesystem, network and process isolation still apply; the only limitation is that /proc is inherited from the container rather than mounted fresh.
allowUnsandboxedCommands is false to prevent Claude from retrying failed sandboxed commands without the sandbox.
Deny rules in the permissions block only block Claude’s built-in tools, not bash subprocesses.
For example, Read(./.env) blocks the Read tool but cat .env bypasses it.
The sandbox denyRead list enforces file access at the OS level regardless of how the file is accessed.
Use both layers: permissions for tool gating, sandbox for OS-level enforcement.
“permissions“ example block prevents commands that would modify the container environment.
Package installation, sudo and container runtime commands are denied.
Git staging and committing require approval.
additionalDirectories extends scope to paths the container uses for configuration and mounted files.
“hooks“ example injects project context at session start, blocks secret access and logs tool calls.
SessionStart outputs the project spec, settings and GPU information into the session.
PreToolUse blocks commands that reference secret environment variables from spec.yaml.
Step Three: Create hook scripts.
The SessionStart hook checks whether the container is an AI Workbench project and injects context into the session. It checks the project repository and creates a
CLAUDE.mdfile and.claudesubfolder if they don’t exist. It also enters the project spec and settings, and reports GPU availability.The PreToolUse hook blocks bash commands that reference secret environment variables defined in spec.yaml. It parses the project’s
spec.yamlfor secret variable names and rejects any bash command that references them. It also blocks environment-dumping commands (env,printenv,set,declare -p) when secrets are present.
Step Four: Create the SKILL.md file.
The skill tells Claude about the constraints of the project container.
Step Five: Optionally, create a references/config-files.md file.
This gives Claude detailed knowledge about each AI Workbench configuration file.
It documents location, format, edit constraints and effect of changes for files like spec.yaml, apt.txt, requirements.txt and build scripts.
See the full file in the template repository.
Step Six: Publish the repository.
Push the repository to GitHub or GitLab. It should be accessible from inside the project container during the build.
Include the Configuration in the Build
Step One: Add the clone to postBuild.bash.
Add the following command after the Claude Code installation commands from Install Claude Code in a Project Container.
Step Two: Build the container.
- Select Project Tab > Project Container > Build
Step Three: Verify the configuration is in place.
- Open a terminal in the container
- Run
cat ~/.claude/settings.jsonto verify the settings file is present - Run
claudeto start a session and confirm the SessionStart hook outputs project context
Success: The sandbox configuration repository is cloned into the container at build time. Claude Code starts with your settings, hooks and skills in place.
The build clones a fresh copy of the configuration every time.
If you want runtime changes (such as conversation history) to persist across restarts, set a volume mount for ~/.claude/.
Select Project Tab > Project Container > Mounts > Add with Type > Volume Mount and Target Directory set to the configuration directory.
Note that volume mount contents take precedence over build output — to reset to the build-time state, remove the volume mount and rebuild.
Related Topics
- Install Claude Code in a Project Container - Install Claude Code in a project container
- Sandboxing Agents with AI Workbench - How agent sandboxing works in AI Workbench
- Claude Code Settings Reference - Full settings documentation
- Claude Code Hooks Guide - Hooks documentation
- Claude Code Permissions - Permissions documentation