feat: sandbox mode for isolated Claude Code execution #182

Open
opened 2026-03-06 09:28:25 -08:00 by hikari · 0 comments
Owner

Overview

Inspired by ralph-tui's sandbox execution mode, this adds a Sandbox Mode that runs Claude Code in an isolated environment, preventing it from making unintended changes to the host system during autonomous or task-loop sessions.

User Story

As a developer using the automated task loop, I want Claude Code to run in a sandboxed environment so that autonomous tasks cannot accidentally modify system files, install packages globally, or make destructive changes outside the project directory.

Implementation Details

Linux: bwrap (bubblewrap)

On Linux, use bwrap to create a lightweight container:

bwrap \
  --bind /home/user/project /home/user/project \
  --bind /usr /usr \
  --ro-bind /etc /etc \
  --proc /proc \
  --dev /dev \
  --unshare-net \
  -- claude --output-format stream-json ...

Key restrictions:

  • Bind-mount only the project directory as read-write
  • Make the rest of the filesystem read-only
  • Optionally restrict network access (--unshare-net) for offline tasks
  • Block writes outside the project root

macOS: sandbox-exec

On macOS, use the built-in sandbox-exec with a profile that restricts file writes to the project directory.

Windows

Sandbox support on Windows is more complex; defer to a future issue. On Windows, sandbox mode should show an "unsupported" message rather than failing silently.

Configuration Options

Add to Config Sidebar under a new "Security" section:

  • Enable Sandbox Mode toggle (off by default)
  • Allow Network Access toggle (only visible when sandbox is enabled)
  • Additional Allowed Paths list (allow read-write access to specific paths beyond the project root, e.g. ~/.config)

Behaviour

  • When sandbox mode is enabled, all Claude Code processes are launched via bwrap/sandbox-exec
  • A sandbox indicator (🔒) appears in the status bar when active
  • If bwrap is not installed, show a friendly error with install instructions
  • Sandbox mode is especially recommended when using the Task Loop

Acceptance Criteria

  • Sandbox mode available as a settings toggle
  • On Linux, Claude Code runs via bwrap when enabled
  • On macOS, Claude Code runs via sandbox-exec when enabled
  • On Windows, a clear "not supported" message is shown
  • Status bar indicator shows sandbox is active
  • Network restriction can be toggled independently
  • Graceful error if bwrap/sandbox-exec is not installed
  • Tests written for command-building logic (E2E integration test pattern)

This issue was created with help from Hikari~ 🌸

## Overview Inspired by [ralph-tui](https://github.com/subsy/ralph-tui)'s sandbox execution mode, this adds a **Sandbox Mode** that runs Claude Code in an isolated environment, preventing it from making unintended changes to the host system during autonomous or task-loop sessions. ## User Story As a developer using the automated task loop, I want Claude Code to run in a sandboxed environment so that autonomous tasks cannot accidentally modify system files, install packages globally, or make destructive changes outside the project directory. ## Implementation Details ### Linux: `bwrap` (bubblewrap) On Linux, use [`bwrap`](https://github.com/containers/bubblewrap) to create a lightweight container: ```bash bwrap \ --bind /home/user/project /home/user/project \ --bind /usr /usr \ --ro-bind /etc /etc \ --proc /proc \ --dev /dev \ --unshare-net \ -- claude --output-format stream-json ... ``` Key restrictions: - Bind-mount only the project directory as read-write - Make the rest of the filesystem read-only - Optionally restrict network access (`--unshare-net`) for offline tasks - Block writes outside the project root ### macOS: `sandbox-exec` On macOS, use the built-in `sandbox-exec` with a profile that restricts file writes to the project directory. ### Windows Sandbox support on Windows is more complex; defer to a future issue. On Windows, sandbox mode should show an "unsupported" message rather than failing silently. ### Configuration Options Add to **Config Sidebar** under a new "Security" section: - **Enable Sandbox Mode** toggle (off by default) - **Allow Network Access** toggle (only visible when sandbox is enabled) - **Additional Allowed Paths** list (allow read-write access to specific paths beyond the project root, e.g. `~/.config`) ### Behaviour - When sandbox mode is enabled, all Claude Code processes are launched via `bwrap`/`sandbox-exec` - A **sandbox indicator** (🔒) appears in the status bar when active - If `bwrap` is not installed, show a friendly error with install instructions - Sandbox mode is especially recommended when using the Task Loop ## Acceptance Criteria - [ ] Sandbox mode available as a settings toggle - [ ] On Linux, Claude Code runs via `bwrap` when enabled - [ ] On macOS, Claude Code runs via `sandbox-exec` when enabled - [ ] On Windows, a clear "not supported" message is shown - [ ] Status bar indicator shows sandbox is active - [ ] Network restriction can be toggled independently - [ ] Graceful error if `bwrap`/`sandbox-exec` is not installed - [ ] Tests written for command-building logic (E2E integration test pattern) ✨ This issue was created with help from Hikari~ 🌸
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: nhcarrigan/hikari-desktop#182