Skip to content

dhuangca/dshell

Repository files navigation

dshell - Secure Shell with Filesystem Isolation

A security-focused shell that uses Linux Landlock to provide kernel-enforced filesystem isolation for interactive commands like Claude Code, vim, and other tools.

What It Does

πŸ”’ Restricts commands to current directory - Interactive commands can only access files in your working directory

βœ… Kernel-enforced - Uses Linux Landlock LSM, cannot be bypassed

πŸ”‘ Environment filtering - Controls which environment variables commands can see

βš™οΈ Configurable - Easy to add custom allowed paths for tools like Claude

Quick Start

# Build
cargo build --release

# Run
cd ~/my-project
/work/oor/shell/target/release/dshell

# Use Claude safely - it can only access ~/my-project
dshell> claude

Features

  • Filesystem Isolation (Landlock) - Restricts interactive commands to current directory
  • Environment Variable Filtering - Controls access to sensitive environment variables
  • Configurable Paths - Add custom paths for tools that need config access
  • Pre-configured for Claude - Works with Claude Code out of the box
  • Good Error Messages - Clear feedback when things go wrong
  • Graceful Fallback - Works on older systems without Landlock (with warnings)

Example Use Case

# You're working on a sensitive project
cd ~/work/sensitive-project

# Run dshell
dshell

# Run Claude - it's isolated to this project only
dshell> claude

# Claude can access:
# βœ… ~/work/sensitive-project/* (current directory)
# βœ… ~/.claude/ (its config)
# βœ… System binaries (/usr/bin, etc.)

# Claude CANNOT access:
# ❌ ~/work/other-project/ (different project)
# ❌ ~/Documents/ (outside project)
# ❌ ../parent/ (parent directories)

Requirements

  • OS: Linux
  • Kernel: 5.13+ (for Landlock) - graceful fallback on older kernels
  • Build: Rust 1.70+
  • Runtime: Regular user, no root needed

Documentation

πŸ“– INSTALL.md - Installation and usage guide πŸ“– USAGE.md - How to use dshell πŸ“– CONFIGURING_PATHS.md - How to add custom paths πŸ“– FILESYSTEM_ISOLATION_PLAN.md - Technical details

Installation

Quick Install (User)

cargo build --release
cp target/release/dshell ~/.local/bin/
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

System-wide Install

cargo build --release
sudo cp target/release/dshell /usr/local/bin/

See INSTALL.md for more options.

Configuration

Configuration is loaded from ~/.config/dshell/config.toml. A template is provided at config.toml.example.

# Copy the example config
cp config.toml.example ~/.config/dshell/config.toml

# Edit to add your own paths
nano ~/.config/dshell/config.toml

Example configuration:

# Interactive commands that run with filesystem isolation
interactive_commands = ["claude", "vim", "bash", "python", ...]

# Additional paths allowed for isolated commands
additional_allowed_paths = [
    "~/.claude",           # Claude config
    "~/.cargo",            # Rust toolchain
    "~/.rustup",           # Rust toolchain manager
    "~/.nvm",              # Node.js
    # Add your own paths here
]

See CONFIGURING_PATHS.md for details.

How It Works

Isolation Levels

Without Landlock (Linux <5.13):

  • ⚠️ Environment variables filtered
  • ⚠️ Working directory set
  • ❌ NO filesystem isolation

With Landlock (Linux 5.13+):

  • βœ… Environment variables filtered
  • βœ… Working directory set
  • βœ… Filesystem isolated by kernel

What Gets Isolated

Interactive commands (configured in src/config.rs):

  • claude, vim, nvim, nano, emacs
  • bash, sh, python, node
  • less, more, man, ssh

Regular commands (NOT isolated):

  • cat, ls, grep, find, cp, mv
  • Standard utilities

Security

βœ… What It Protects Against

  • Prevents Claude/tools from accessing files outside current directory
  • Prevents reading ../sensitive-data/secrets.txt
  • Prevents writing to /etc/ or other system directories
  • Blocks access to other projects or home directory files
  • Filters sensitive environment variables

⚠️ Limitations

  • Linux-only (Landlock doesn't exist on macOS/Windows)
  • Requires kernel 5.13+ for full isolation
  • Can't restrict network access (tools can still make API calls)
  • System paths accessible (needed for binaries to run)

See technical details in FILESYSTEM_ISOLATION_PLAN.md.

Built-in Commands

help              # Show help
env               # List environment variables
security          # Show security status
allow <VAR>       # Allow environment variable
deny <VAR>        # Deny environment variable
export KEY=VALUE  # Set environment variable
echo $VAR         # Echo with variable expansion
exit              # Exit dshell

Example Session

$ cd ~/my-app
$ dshell

Welcome to dshell terminal!

πŸ”’ Security Features:

  β€’ Environment Variables: Filtered by default
  β€’ Filesystem Isolation: ENABLED (Landlock)
    Landlock ABI version: V2
    βœ“ Kernel-enforced - cannot be bypassed

dshell> security
Security Status:
  Environment Access: Selective
  Allowed: HOME, PATH, USER, SHELL, TERM, LANG, EDITOR, COLORTERM
  Plus Rust toolchain vars: RUSTUP_HOME, CARGO_HOME, etc.

dshell> claude
πŸ”’ Filesystem isolated to: /home/user/my-app
# Claude starts and can only access /home/user/my-app

dshell> exit
$

Claude Code Configuration

If you need to configure Claude Code to use a specific HOME directory, add the following to your Claude Code settings:

File location: .claude/settings.json (in your project) or ~/.claude/settings.json (global)

{
  "env": {
    "HOME": "/home/dandan"
  }
}

This ensures Claude Code uses the correct HOME path for all commands. See Claude Code settings documentation for more details.

Troubleshooting

Build fails with "linker cc not found"?

If you encounter linker errors during build, you may need to configure cargo to use your system's GCC linker explicitly.

Create .cargo/config.toml in your project directory:

[target.x86_64-unknown-linux-gnu]
linker = "/usr/bin/gcc"

Note: This configuration is target-specific and only affects builds for x86_64-unknown-linux-gnu (64-bit Linux). It will not impact builds for other platforms like Windows, macOS, or ARM architectures. Each platform uses its own default linker.

For CI/CD or temporary builds, you can also use an environment variable:

CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=/usr/bin/gcc cargo build

Or ensure /usr/bin is in your PATH when building:

PATH="/usr/bin:$PATH" cargo build

Landlock not available?

Check your kernel:

uname -r  # Need 5.13+
cat /sys/kernel/security/lsm | grep landlock

Command fails?

Check the error message - it will tell you if:

  • Command not found (not in PATH)
  • Permission denied (Landlock blocking it)
  • Missing environment variable

Claude can't access API?

Make sure these are in additional_allowed_paths in ~/.config/dshell/config.toml:

  • ~/.claude
  • ~/.claude.json
  • ~/.nvm
  • ~/.npm

No rebuild needed - just restart dshell.

Rust commands (cargo, rustc) not working?

The shell now includes Rust environment variables by default (RUSTUP_HOME, CARGO_HOME, etc.).

Make sure these paths are in additional_allowed_paths in ~/.config/dshell/config.toml:

  • ~/.cargo
  • ~/.rustup

These are included in the default config template.

If cargo is still not found, ensure ~/.cargo/bin is in your PATH:

echo $PATH | grep cargo

Contributing

This was built to safely run Claude Code and similar AI coding assistants in isolated environments.

Ideas for improvements:

  • Network isolation (Landlock ABI V4+)
  • Dynamic path detection
  • Configuration file instead of recompiling
  • More granular permissions (read-only vs read-write)

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Acknowledgments

Built with:

  • Landlock - Linux kernel LSM for filesystem isolation
  • crossterm - Terminal handling
  • Rust - Systems programming language

Generated with assistance from Claude Code πŸ€–

About

security shell for claude

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages