Run Claude Code in an isolated environment using dedicated Linux users with optional namespace/container isolation.
Claude Code is powerful but can execute arbitrary code on your machine. clsecure provides defense-in-depth:
- π Dedicated user per project - File access isolated from your main user
- π Network isolation - Prevent data exfiltration (optional)
- π¦ Namespace sandboxing - Process, mount, and IPC isolation
- π³ Container option - Maximum isolation with podman
# Download and install
curl -fsSL https://raw.githubusercontent.com/pablopda/clsecure/main/clsecure -o clsecure
chmod +x clsecure
sudo install -m 755 clsecure /usr/local/bin/
# Install dependencies (for namespace mode)
sudo apt install firejail# Navigate to your git project
cd ~/projects/my-app
# Run Claude Code in isolation
clsecure| Mode | Security | Requirements | Description |
|---|---|---|---|
user |
βββ | sudo | Dedicated Linux user per project |
namespace |
ββββ | firejail | User + firejail sandbox (default) |
container |
βββββ | podman | User + rootless container |
clsecure [OPTIONS]
Options:
--help, -h Show help
--list, -l List worker users
--cleanup Remove worker users
--mode MODE user | namespace (default) | container
--allow-network Allow network access
--allow-docker Allow Docker access
--info Show isolation details# Default (namespace isolation)
clsecure
# With network access (for git push, npm install)
clsecure --allow-network
# Maximum security (container isolation)
clsecure --mode container
# Simple isolation (user only)
clsecure --mode user
# List all worker users
clsecure --list
# Clean up workers
clsecure --cleanupYou can configure persistent settings and custom setup scripts in ~/.config/clsecure/config.
Create ~/.config/clsecure/config:
# ~/.config/clsecure/config
# Default isolation mode (user, namespace, container)
mode = namespace
# Allow network access by default
network = true
# Path to a custom setup script (executed inside the worker environment)
setup_script = /home/user/.config/clsecure/install_private_tools.shYou can use the setup_script hook to install private tools or configure the environment. The script runs as the worker user inside the isolated environment.
Some MCP servers are started via npx (for example @upstash/context7-mcp). For these to work inside the worker user:
- Your project
.mcp.jsonshould use portable commands likenpx(not absolute paths like/home/user/.nvm/.../npx). - The worker environment must have Node + npx available on
PATH.
Recommended setup for multi-user portability:
- Install Node in shared Linuxbrew (works well with
clsecuresince workers alreadyeval "$(brew shellenv)"):sudo -H -u linuxbrew /home/linuxbrew/.linuxbrew/bin/brew install node
Alternative options:
- Install system-wide Node:
sudo apt-get install -y nodejs npm - Or install Node per-worker using the
setup_scripthook (e.g. usingnvminside the worker userβs$HOME)
Key Feature: If you have gh (GitHub CLI) installed and authenticated on your host, clsecure will inject your GH_TOKEN into the worker environment during the setup script execution. This allows you to install private tools without exposing credentials in the public codebase.
Example: install_private_tools.sh
#!/bin/bash
# ~/.config/clsecure/install_private_tools.sh
# Install a private tool from GitHub using the injected GH_TOKEN
if command -v gh &>/dev/null && [ -n "$GH_TOKEN" ]; then
echo "Installing private tools..."
# Example: Install a python script from a private repo
# python3 <(gh api repos/my-org/my-private-tool/contents/install.py --jq '.content' | base64 -d)
else
echo "Skipping private install (GH_TOKEN missing)"
fiβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Your Machine β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β claude-worker-myproject (dedicated user) β β
β β βββββββββββββββββββββββββββββββββββββββββββββββ β β
β β β Firejail Namespace (optional) β β β
β β β βββββββββββββββββββββββββββββββββββββββ β β β
β β β β Claude Code β β β β
β β β β - Isolated filesystem β β β β
β β β β - No network (unless allowed) β β β β
β β β β - Restricted capabilities β β β β
β β β βββββββββββββββββββββββββββββββββββββββ β β β
β β βββββββββββββββββββββββββββββββββββββββββββββββ β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Creates a dedicated Linux user:
claude-worker-<project> - Clones your git repo (with submodules) to the worker's home
- Syncs uncommitted changes
- Runs Claude Code as that user with restricted permissions
- After session: syncs changes back and offers to commit
- Linux (Ubuntu/Debian/Fedora/Arch)
git,rsync,sudo- For namespace mode:
firejail - For container mode:
podman
clsecure uses a modular architecture for maintainability:
clsecure/
βββ clsecure # Built single-file (for distribution)
βββ clsecure-src # Modular main script (for development)
βββ lib/ # Module library
β βββ vars.sh # Variable initialization
β βββ logging.sh # Logging functions
β βββ lock.sh # Lock management
β βββ config.sh # Configuration loading
β βββ worker.sh # Worker user management
β βββ git.sh # Git operations
β βββ sanitize.sh # Path sanitization
β βββ deps.sh # Dependency installation
β βββ isolation.sh # Isolation execution
β βββ sync.sh # Sync-back logic
βββ build.sh # Build script (generates clsecure from modules)
- Edit modules: Modify
clsecure-srcand files inlib/ - Rebuild: Run
./build.shto regenerateclsecure - Test: Run
./run_tests.shto execute unit tests - Commit: Pre-commit hook verifies build consistency
# Install bats (test framework)
sudo apt install bats # Ubuntu/Debian
brew install bats-core # macOS
# Run all tests
./run_tests.sh# Rebuild clsecure from modules
./build.shThe build script concatenates all modules into a single-file clsecure for distribution, maintaining backwards compatibility.
Contributions are welcome! Please feel free to submit a Pull Request.
- Follow bash best practices (
set -euo pipefail) - Use the logging functions (
log_info,log_warn, etc.) - Keep modules focused and under 300 lines
- Add tests for new functionality
- Run
./build.shbefore committing