Add your description here
Project description
Chuk Virtual Shell ๐
A powerful virtual shell environment with MCP (Model Context Protocol) integration, perfect for AI agents and sandboxed execution environments.
๐ Overview
Chuk Virtual Shell provides a complete POSIX-like virtual shell environment designed specifically for AI agents and automation:
- ๐ค MCP Server Integration: Full Model Context Protocol support for AI agents like Claude, Cline, and Aider
- ๐ Persistent Sessions: Stateful command execution with maintained context across interactions
- ๐ User Isolation: Complete session and task isolation between users
- ๐ Virtual Filesystem: Pluggable storage providers (memory, SQLite, S3)
- ๐ฏ 50+ Built-in Commands: Comprehensive Unix-like command set
- โก Advanced I/O: Full pipeline, redirection, and here-doc support
- ๐๏ธ Pre-configured Sandboxes: Ready-to-use secure environments
- ๐ Extensible Architecture: Easy to add custom commands and storage providers
๐ Quick Start
Installation
# Install with uv (recommended)
uv pip install chuk-virtual-shell
# Or with pip
pip install chuk-virtual-shell
# For MCP server functionality, install optional dependency
uv pip install chuk-virtual-shell[mcp-server]
# Or with pip
pip install chuk-virtual-shell[mcp-server]
Basic Usage
# Start interactive shell
uv run chuk-virtual-shell
# Use a pre-configured sandbox
uv run chuk-virtual-shell --sandbox ai_sandbox
# Start MCP server for AI agents
uv run python -m chuk_virtual_shell.mcp_server
MCP Integration for AI Agents
# See examples/mcp_client_demo.py for complete example
from examples.mcp_client_demo import SimpleMCPClient
client = SimpleMCPClient()
await client.start_server()
# Create isolated session
result = await client.call_tool("bash", {"command": "pwd"})
session_id = result["session_id"]
# Commands share state within session
await client.call_tool("bash", {
"command": "export PROJECT=MyApp && mkdir -p /project/src",
"session_id": session_id
})
# State persists across commands
result = await client.call_tool("bash", {
"command": "echo $PROJECT && ls /project",
"session_id": session_id
})
# Output: MyApp\nsrc
Try the Interactive Demo
# Run the complete MCP demonstration
uv run examples/mcp_client_demo.py
# Expected output shows:
# โ
User isolation and session management
# โ
State persistence across commands
# โ
Background task execution
# โ
Multiple concurrent sessions
# โ
Complex multi-step workflows
๐ Key Features
๐ค MCP Server Capabilities
Full Model Context Protocol implementation with user isolation:
# Available MCP tools:
- bash # Execute shell commands with session persistence
- whoami # Get user context and session info
- list_sessions # List all active sessions for current user
- get_session_state # Get session details (pwd, env, lifetime)
- destroy_session # Clean up sessions
- get_task_output # Get background task results
- cancel_task # Cancel running background tasks
User Isolation Features:
- Each user gets isolated sessions and tasks
- Sessions maintain state (PWD, env vars, files) between commands
- Background task execution with streaming output
- Automatic session cleanup on disconnect
- Per-user resource limits and quotas
Advanced Shell Features via MCP:
- Full stderr redirection (
2>,2>>,2>&1) - Combined output redirection (
&>,&>>) - Complex pipelines and command chaining
- Quoted filename support with spaces
- All 50+ built-in shell commands available
๐ Session Management
Stateful sessions that maintain context - essential for AI workflows:
from chuk_virtual_shell.session import ShellSessionManager
from chuk_virtual_shell.shell_interpreter import ShellInterpreter
# Create session manager
manager = ShellSessionManager(shell_factory=lambda: ShellInterpreter())
# Create persistent session
session_id = await manager.create_session()
# Commands share state
await manager.run_command(session_id, "cd /project")
await manager.run_command(session_id, "export API_KEY=secret")
await manager.run_command(session_id, "echo 'data' > file.txt")
# State persists
result = await manager.run_command(session_id, "pwd && echo $API_KEY && cat file.txt")
# Output: /project\nsecret\ndata
๐ Advanced I/O Redirection
Comprehensive redirection support (see docs/features/redirection.md):
# Output redirection
echo "Hello" > output.txt
echo "World" >> output.txt
# Input redirection
sort < unsorted.txt > sorted.txt
# Pipelines
cat data.txt | grep "pattern" | sort | uniq > results.txt
# Here-documents (in scripts)
cat << EOF > config.yaml
server: localhost
port: 8080
EOF
# Advanced redirection
command 2> errors.txt # Stderr redirection
command 2>&1 # Merge stderr to stdout
command &> all_output.txt # Combined output
command 2>> errors.txt # Append stderr
command &>> all.txt # Append combined output
๐ญ Quoting and Escaping
Full quoting semantics (see docs/features/quoting.md):
# Single quotes - literal
echo 'Hello $USER' # Output: Hello $USER
# Double quotes - with expansion
echo "Hello $USER" # Output: Hello alice
# Backslash escaping
echo "Price: \$100" # Output: Price: $100
echo file\ with\ spaces.txt # Output: file with spaces.txt
# Mixed quoting
echo "It's"' a nice day' # Output: It's a nice day
๐๏ธ Pre-configured Sandboxes
Ready-to-use secure environments:
# config/ai_sandbox.yaml - Restricted AI agent environment
environment:
HOME: /sandbox
USER: ai
PATH: /bin
SANDBOX_MODE: restricted
filesystem:
provider: memory
initialization:
- mkdir -p /sandbox/workspace
- echo "AI Sandbox Ready" > /sandbox/README.txt
Available sandboxes:
ai_sandbox- Restricted environment for AI code executiondefault- Balanced development environmentreadonly- Read-only exploratione2b- E2B.dev compatible environmenttigris- Tigris Data S3-compatible storage
๐ Feature Matrix
| Feature Category | Feature | Status | Notes |
|---|---|---|---|
| MCP Integration | MCP Server | โ | Full protocol support |
| User Isolation | โ | Session & task isolation | |
| Background Tasks | โ | Async execution with streaming | |
| Session Persistence | โ | State maintained across commands | |
| I/O Redirection | Basic pipes (|) |
โ | Multi-stage pipelines |
Output redirect (>, >>) |
โ | Write and append | |
Input redirect (<) |
โ | Read from files | |
Stderr redirect (2>, 2>>) |
โ | Full stderr redirection | |
Combined (2>&1, &>, &>>) |
โ | Merge stdout/stderr | |
Here-docs (<<) |
โก | Works in script runner | |
| Shell Operators | Chaining (&&, ||, ;) |
โ | Full conditional execution |
Command substitution ($()) |
โ | Both syntaxes supported | |
| Variable expansion | โ | $VAR, ${VAR} |
|
Glob patterns (*, ?) |
โ | Full support | |
| Control Flow | if/then/else | โ | Conditional logic |
| for/while loops | โ | Full iteration support | |
| case statements | โ | Pattern matching | |
| Functions | โ | Planned | |
| Commands | File operations | โ | cp, mv, rm, mkdir, touch |
| Text processing | โ | grep, sed, awk, sort, uniq | |
| File viewing | โ | cat, head, tail, more | |
| System utilities | โ | find, which, tree, date |
Legend:
- โ Full Support: Complete implementation with tests
- โก Partial Support: Works with limitations
- ๐ง In Development: Parser/infrastructure ready
- โ Not Supported: Not yet implemented
๐ ๏ธ Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ MCP Client (AI Agent) โ
โโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ MCP Protocol
โโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ MCP Server (chuk_virtual_shell) โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ User Isolation & Session Management โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Shell Interpreter & Command Executor โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Virtual Filesystem (Memory/SQLite/S3) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Documentation
- POSIX Compatibility Matrix - Detailed POSIX.1-2017 compliance
- MCP Integration Guide
- Session Management
- Redirection Guide
- Quoting Guide
- Command Reference
- Sandbox Configuration
- API Documentation
๐งช Testing
# Run all tests
uv run pytest
# Run with coverage
uv run pytest --cov=chuk_virtual_shell
# Run specific test categories
uv run pytest tests/test_mcp_server.py
uv run pytest tests/test_quoting_comprehensive.py
uv run pytest tests/test_advanced_redirection.py
Current test status: 1411 tests passing (18 skipped)
๐ค Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Development Setup
# Clone the repository
git clone https://github.com/chrishayuk/chuk-virtual-shell.git
cd chuk-virtual-shell
# Install with dev dependencies
uv pip install -e ".[dev]"
# Run tests
uv run pytest
# Run linting
uv run ruff check .
# Run type checking
uv run mypy chuk_virtual_shell
๐ง Troubleshooting
MCP Server Issues
Problem: ModuleNotFoundError: No module named 'chuk_mcp_server'
Solution: Install the MCP server optional dependency:
uv pip install chuk-virtual-shell[mcp-server]
# or with pip
pip install chuk-virtual-shell[mcp-server]
Problem: MCP demo fails with JSON decode error
Solution: Ensure the MCP server dependency is installed and the server is accessible:
# Test MCP server directly
uv run python -m chuk_virtual_shell.mcp_server
# Run the interactive demo
uv run examples/mcp_client_demo.py
General Issues
Problem: Command not found errors
Solution: Ensure you're using the correct command syntax. Check available commands:
# In interactive mode
help
# Check specific command help
help ls
Problem: File permission errors
Solution: The virtual filesystem has simulated permissions. Use appropriate commands:
# Create directories with proper paths
mkdir -p /path/to/directory
# Check current working directory
pwd
๐ License
MIT License - see LICENSE for details.
๐ Acknowledgments
- Built for AI agents using Model Context Protocol
- Inspired by Unix shell design principles
- Virtual filesystem powered by chuk-virtual-fs
๐ฎ Contact
- GitHub: @chrishayuk
- Issues: GitHub Issues
Ready to give your AI agents a powerful shell environment? Get started with uv pip install chuk-virtual-shell! ๐
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chuk_virtual_shell-0.1.6.tar.gz.
File metadata
- Download URL: chuk_virtual_shell-0.1.6.tar.gz
- Upload date:
- Size: 269.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ebf859275841932733c6e3ad04c17a061df5d254870fd841e103fd4d39ab8cfb
|
|
| MD5 |
14c251d557ba1e3abee877c013ac4921
|
|
| BLAKE2b-256 |
8463b9f8715252d3ef7b673c4924e7f7d63b74ca8fe7ed8a5e562ef5e7fc2f76
|
File details
Details for the file chuk_virtual_shell-0.1.6-py3-none-any.whl.
File metadata
- Download URL: chuk_virtual_shell-0.1.6-py3-none-any.whl
- Upload date:
- Size: 176.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd854124878bd53306e87462d58efd72592a7ea4c677f096e5ab81267d6c3ac1
|
|
| MD5 |
02e6c83436fd54794af06f57242b2d84
|
|
| BLAKE2b-256 |
a01e5432c57a9953642852a0194fa8e4df4223d0ca00f1ecbeaa4c31404c23dc
|