Securely Execute Shell Commands for AI
MCP server that exposes shell command execution to AI clients with secure-by-default allowlisting, built in Go, runs in Docker or from source.
Why it matters
Bridge AI assistants with your shell environment by providing secure, auditable execution of shell commands. Offers fine-grained control over command execution through allowlists, blocklists, and environment variable configuration.
Outcomes
What it gets done
Execute shell commands with customizable security restrictions.
Generate structured JSON output including stdout, stderr, and exit codes.
Leverage Docker for secure, isolated command execution.
Audit all command executions for security and compliance.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/vb-shell | bash Capabilities
Tools your agent gets
Executes shell commands with customizable security restrictions, returning structured output with stdout, stderr, and exit codes.
Overview
Shell MCP Server
mcp-shell is an MCP server that exposes shell command execution to LLMs with secure-by-default allowlisting. Built in Go on mark3labs/mcp-go, it restricts execution to a narrow set of read-only utilities (ls, cat, grep, find, head, tail) unless you explicitly widen the policy via YAML config or opt into unrestricted mode. In secure mode, commands are parsed into a shell AST and only single, fully-literal simple commands are accepted - no pipes, substitution, redirection, or globs. Interpreters and alias-capable tools are hard-denied even if allowlisted. The tool accepts a command string and a Use mcp-shell when you need AI-assisted file inspection, log searching, or diagnostic commands in a controlled environment where you cannot afford arbitrary code execution - development workflows, CI pipelines, or production observability with full audit trails. Do NOT use unrestricted mode in production or add shell interpreters to the allowlist; they bypass secure mode entirely. Pair the Docker image with OS-level sandboxing (read-only FS, dropped capabilities) for defense-in-depth in production deployments.
What it does
mcp-shell is an MCP server that gives LLMs a tool to run shell commands while giving operators fine-grained control over what executes and how. Built on mark3labs/mcp-go and written in Go, it boots in secure mode by default, restricting execution to a narrow allowlist of read-only utilities (ls, cat, grep, find, head, tail). You widen or change that policy with a YAML config file, or opt into fully unrestricted mode explicitly.
When to use - and when NOT to
Use mcp-shell when you need an AI assistant to inspect files, search logs, or run diagnostic commands in a controlled environment. It fits scenarios where you want shell access but cannot afford arbitrary code execution - development workflows, CI pipelines, or production observability where you audit every command. Do NOT use unrestricted mode (MCP_SHELL_ALLOW_UNSAFE=true) in production; it disables all validation and is only safe for local development. Do NOT add shell interpreters (bash, sh, python, perl, ruby, node) or alias-capable tools (git) to the allowlist - they bypass secure mode entirely by executing whatever they are handed.
Inputs and outputs
The tool accepts a command string (required) and a base64 boolean to encode stdout/stderr as base64. The response includes status, exit_code, stdout, stderr, command, execution_time, and optional security_info.
Integrations
Claude Desktop: Add to your MCP config:
{
"mcpServers": {
"shell": {
"command": "docker",
"args": ["run", "--rm", "-i", "sonirico/mcp-shell:latest"],
"env": { "MCP_SHELL_LOG_LEVEL": "info" }
}
}
}
For custom config, mount the file and set the env:
{
"command": "docker",
"args": ["run", "--rm", "-i", "-v", "/path/to/security.yaml:/etc/mcp-shell/security.yaml", "-e", "MCP_SHELL_SEC_CONFIG_FILE=/etc/mcp-shell/security.yaml", "sonirico/mcp-shell:latest"]
}
Docker: Run with:
docker run -it --rm -v /tmp/mcp-workspace:/tmp/mcp-workspace sonirico/mcp-shell:latest
From source:
git clone https://github.com/sonirico/mcp-shell && cd mcp-shell
make install
mcp-shell
Configuration modes
Secure mode (recommended) - no shell interpretation, executable allowlist only:
security:
enabled: true
use_shell_execution: false
allowed_executables:
- ls
- cat
- grep
- find
- echo
blocked_patterns:
- '(^|\s)remote\s+(-v|--verbose)(\s|$)'
max_execution_time: 30s
max_output_size: 1048576
working_directory: /tmp/mcp-workspace
audit_log: true
In secure mode, the command is parsed into a shell AST and only a single, fully-literal simple command is accepted (no pipes, lists, substitution, redirection or globs); its executable must be on the allowlist. Interpreters are hard-denied even if allowlisted, and per-tool policies strip escape hatches (git -c, find -exec, tar --checkpoint-action).
Legacy mode - shell execution, allowlist/blocklist by command string (vulnerable to injection if not careful):
security:
enabled: true
use_shell_execution: true
allowed_commands: [ls, cat, grep, echo]
blocked_patterns: ['rm\s+-rf', 'sudo\s+']
max_execution_time: 30s
audit_log: true
Who it's for
DevOps engineers and SREs who need AI-assisted diagnostics without handing over root access. Developers building AI agents that interact with filesystems or logs in a sandboxed way. Security-conscious teams who want audit logs and allowlist enforcement before granting shell access to an LLM. The Docker image runs as non-root on Alpine; pair it with OS-level sandboxing (read-only FS, dropped capabilities) for defense-in-depth.
Source README
mcp-shell
MCP server that runs shell commands. Your LLM gets a tool; you get control over what runs and how.
Built on mark3labs/mcp-go. Written in Go.
Run it
Docker (easiest):
docker run -it --rm -v /tmp/mcp-workspace:/tmp/mcp-workspace sonirico/mcp-shell:latest
From source:
git clone https://github.com/sonirico/mcp-shell && cd mcp-shell
make install
mcp-shell
Configure it
Secure mode is the default. With no config file, mcp-shell boots in secure
mode restricted to a narrow allowlist of read-only utilities (ls, cat,grep, find, head, tail, ...). You only need a config file to widen or
change that policy. To run fully unrestricted you must opt in explicitly:
MCP_SHELL_ALLOW_UNSAFE=true mcp-shell # disables all validation - do not use in production
To customize the policy, point to a YAML config:
export MCP_SHELL_SEC_CONFIG_FILE=/path/to/security.yaml
mcp-shell
Secure mode (recommended) - no shell interpretation, executable allowlist only:
security:
enabled: true
use_shell_execution: false
allowed_executables:
- ls
- cat
- grep
- find
- echo
# WARNING: never add shell/language interpreters (bash, sh, python, perl,
# ruby, node) or alias-capable tools (git) here - the interpreter executes
# whatever it is handed, bypassing secure mode entirely. mcp-shell warns at
# startup if it finds one.
blocked_patterns: # optional: restrict args on allowed commands
- '(^|\s)remote\s+(-v|--verbose)(\s|$)'
max_execution_time: 30s
max_output_size: 1048576
working_directory: /tmp/mcp-workspace
audit_log: true
Legacy mode - shell execution, allowlist/blocklist by command string (vulnerable to injection if not careful):
security:
enabled: true
use_shell_execution: true
allowed_commands: [ls, cat, grep, echo]
blocked_patterns: ['rm\s+-rf', 'sudo\s+']
max_execution_time: 30s
audit_log: true
Wire it up
Claude Desktop - add to your MCP config:
{
"mcpServers": {
"shell": {
"command": "docker",
"args": ["run", "--rm", "-i", "sonirico/mcp-shell:latest"],
"env": { "MCP_SHELL_LOG_LEVEL": "info" }
}
}
}
For custom config, mount the file and set the env:
{
"command": "docker",
"args": ["run", "--rm", "-i", "-v", "/path/to/security.yaml:/etc/mcp-shell/security.yaml", "-e", "MCP_SHELL_SEC_CONFIG_FILE=/etc/mcp-shell/security.yaml", "sonirico/mcp-shell:latest"]
}
Tool API
| Parameter | Type | Description |
|---|---|---|
command |
string | Shell command to run (required) |
base64 |
boolean | Encode stdout/stderr as base64 (default: false) |
Response includes status, exit_code, stdout, stderr, command, execution_time, and optional security_info.
Environment variables
| Variable | Description |
|---|---|
MCP_SHELL_SEC_CONFIG_FILE |
Path to security YAML (overrides built-in secure defaults) |
MCP_SHELL_ALLOW_UNSAFE |
Set true to disable all validation and run unrestricted (opt-in) |
MCP_SHELL_SERVER_NAME |
Server name (default: "mcp-shell ๐") |
MCP_SHELL_LOG_LEVEL |
debug, info, warn, error, fatal |
MCP_SHELL_LOG_FORMAT |
json, console |
MCP_SHELL_LOG_OUTPUT |
stdout, stderr, file |
Development
make install dev-tools # deps + goimports, golines
make fmt test lint
make docker-build # build image locally
make release # binary + docker image
Security
- Default: Secure mode, restricted to a narrow allowlist of read-only utilities. No interpreters.
- Secure mode (
use_shell_execution: false): the command is parsed into a shell AST and only a single, fully-literal simple command is accepted (no pipes, lists, substitution, redirection or globs); its executable must be on the allowlist. Interpreters (bash/sh/python) are hard-denied even if allowlisted, and per-tool policies strip escape hatches (git -c,find -exec,tar --checkpoint-action). This is an early-reject layer, not a sandbox. - Unrestricted: Only via
MCP_SHELL_ALLOW_UNSAFE=true. Full access; fine for local dev, dangerous otherwise. - Docker: Runs as non-root, Alpine-based. Use it in production. Best paired with an OS sandbox (read-only FS, dropped caps) as defense-in-depth.
FAQ
Common questions
Discussion
Questions & comments ยท 0
Sign In Sign in to leave a comment.