cmd-exec-mcp
Enables isolated command execution inside Docker containers via the execute_sandbox tool, with configurable images, mounts, and security restrictions.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@cmd-exec-mcprun 'ls -la' in /tmp"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
cmd-exec-mcp
English
A simple command execution MCP server supporting local execution, Docker/OpenSandbox sandbox isolation, and SSH remote execution.
Features
Local (
execute_local): Execute commands on the host machine,cwdrequiredSandbox (
execute_sandbox): Isolated execution in Docker containers or OpenSandbox, ephemeralRemote (
execute_remote): Execute commands via SSH on remote servers, supports standard/custom dual-mode configSecurity mode: restricted (whitelist + blacklist) / full mode
Sequential / parallel execution
Timeout control
Session detach: background long-running processes with read/send/kill
Agent Skill:
skills/cmd-exec-mcp/SKILL.md— quick reference for AI agentsLogging
Installation
git clone https://github.com/YC-CLT/cmd-exec-mcp.git
cd cmd-exec-mcp
uv syncMCP Client Configuration
{
"mcpServers": {
"cmd-exec-mcp": {
"command": "uv",
"args": ["run", "--directory", "D:\\your_path\\cmd-exec-mcp", "main.py"]
}
}
}Configuration
Edit config.py:
Config | Default | Description |
|
| Security mode: |
|
| List mode: |
|
| Whitelist commands |
|
| Blacklist commands |
|
| Force shell: |
|
| WSL distro name (when |
|
| WSL username (when |
|
| Sandbox backend: |
|
| Docker sandbox security mode |
|
| Docker sandbox list mode |
|
| Docker sandbox blacklist |
|
| Docker sandbox whitelist |
|
| Docker sandbox default image |
|
| Mount directory ( |
|
| Docker sandbox startup prefix (mirrors, etc.) |
|
| OpenSandbox template image |
|
| OpenSandbox entrypoint script |
|
| OpenSandbox runtime versions + mirrors |
|
| OpenSandbox Server host |
|
| OpenSandbox Server port |
|
| OpenSandbox API Key (required for production) |
|
| Server config file path, falls back to |
|
| Max seconds to wait for server ready |
|
| Idle seconds before auto-shutdown, -1 never |
|
| Timeout in seconds (-1 for unlimited) |
|
| stdout truncation length when using |
|
| Session alive timeout in seconds, -1 for unlimited |
|
| Max lines buffered per session |
|
| Max bytes buffered per session (10 MB) |
|
| Return field toggles |
| — | SSH default target |
|
| SSH default username |
|
| SSH default port |
| — | SSH key path or password string |
|
| Skip known_hosts check |
|
| Persistent SSH connection |
|
| SSH connection timeout in seconds |
|
| Log file path |
|
| Log level |
OpenSandbox Prerequisites
To use the OpenSandbox backend (SANDBOX_BACKEND = "opensandbox"):
Prerequisite: Docker Desktop installed and running
Install the server (global):
uv tool install opensandbox-serverDeploy config: defaults to project
.sandbox.toml, falls back to~/.sandbox.toml. Override inconfig.py→SANDBOX_CONFIG_PATHSwitch backend:
config.py→SANDBOX_BACKEND = "opensandbox"API Key: can be arbitrary for local dev, but don't leave it empty or it will block for manual confirmation; set
SANDBOX_OPEN_API_KEYin production
opensandbox-serveris started automatically on firstexecute_sandboxcall and auto-shuts down afterSANDBOX_OPEN_SERVER_IDLE_TIMEOUTseconds of inactivity (default 600).
SSH Remote Execution Prerequisites
Configure
~/.ssh/configwith Host alias, or setSSH_DEFAULT_TARGETinconfig.py(format:[user@]host[:port])Or set environment variables:
SSH_DEFAULT_TARGET,SSH_DEFAULT_USER,SSH_DEFAULT_PORT,SSH_DEFAULT_KEY,SSH_DEFAULT_NO_KNOWN_HOSTS
Tools
execute_local
Execute a command on the host machine.
{
"command": "echo hello",
"parallel": false,
"timeout": 30,
"cwd": "/tmp",
"env": { "KEY": "value" },
"fields": { "stdout": true, "stderr": false }
}Param | Type | Default | Description |
| str | required | Command, use |
| str | required | Working directory |
| bool | false | Run commands in parallel |
| int | 30 | Timeout in seconds, -1 for unlimited |
| dict | null | Environment variables |
| dict | null | Return field filter |
| str | null | Override shell: |
| str | "" | Write full stdout to disk, return truncated preview |
| bool | false | Run as background session |
| str | null | Session ID for read/send/kill |
| str | "send" |
|
| int | 300 | Session alive timeout in seconds |
execute_sandbox
Execute a command in a sandbox (Docker/OpenSandbox, determined by SANDBOX_BACKEND).
{
"command": "echo hello",
"parallel": false,
"timeout": 30,
"env": { "KEY": "value" },
"fields": { "stdout": true, "stderr": false }
}Param | Type | Default | Description |
| str | required | Command |
| bool | false | Run in parallel |
| int | 30 | Timeout in seconds |
| dict | null | Environment variables |
| dict | null | Return field filter |
| str | "" | Write full stdout to disk, return truncated preview |
| bool | false | Run as background session |
| str | null | Session ID for read/send/kill |
| str | "send" |
|
| int | 300 | Session alive timeout in seconds |
execute_remote
Execute a command on a remote server via SSH. See SSH prerequisites above.
{
"command": "ls -la",
"parallel": false,
"timeout": 30,
"env": { "KEY": "value" },
"fields": { "stdout": true, "stderr": false }
}Param | Type | Default | Description |
| str | required | Command |
| bool | false | Run in parallel |
| int | 30 | Timeout in seconds |
| dict | null | Environment variables |
| dict | null | Return field filter |
| str | "" | Write full stdout to disk, return truncated preview |
| bool | false | Run as background session |
| str | null | Session ID for read/send/kill |
| str | "send" |
|
| int | 300 | Session alive timeout in seconds |
Session Detach
Run long-lived background processes (e.g., dev servers, REPLs) as sessions:
// Start a background session
{
"command": "python -m http.server 8080",
"cwd": "/tmp",
"detach": true
}
// Returns: {"session_id": "abc123"}
// Read output
{
"session_id": "abc123",
"action": "read"
}
// Send input
{
"session_id": "abc123",
"action": "send",
"command": "some input\n"
}
// Kill session
{
"session_id": "abc123",
"action": "kill"
}Sessions auto-terminate after alive_timeout seconds of inactivity (default 300, -1 for unlimited). Output is buffered up to SESSION_MAX_OUTPUT_BYTES.
Testing
uv run pytest tests/ -vNon-Interactive Execution
For non-session commands, stdin is set to /dev/null — interactive commands will fail or timeout. Use session detach (see above) for interactive workflows (REPLs, shells, etc.). For one-shot commands, add flags to skip prompts:
Command | Flag | Notes |
|
| Auto-confirm |
|
| Use with caution |
|
| Non-interactive, fail if password needed |
| — | Non-interactive by default |
| — | Blacklisted by default |
Logging
Logs are written to log.txt in the project root, format:
2026-07-30 12:00:00 [INFO] local: execute: echo hello
2026-07-30 12:00:00 [INFO] local: exit_code=0 duration=0.012License
MIT
Related MCP server: dynamic-mcp
中文
一个简单的命令执行 MCP,支持本地执行、纯 Docker/OpenSandbox 沙箱隔离执行和 SSH 远程执行。
功能
本地执行 (
execute_local): 在宿主机执行命令,cwd 必填沙箱执行 (
execute_sandbox): 在 Docker 容器或 OpenSandbox 沙箱中隔离执行,用完即焚远程执行 (
execute_remote): 通过 SSH 在远程服务器执行命令,支持 standard/custom 双模式配置安全模式: 受限模式(白名单+黑名单)/ 完全模式
单步/并行执行
超时控制
会话分离:后台长时进程,支持 read/send/kill
Agent Skill:
skills/cmd-exec-mcp/SKILL.md— AI Agent 快速参考指南日志记录
安装
git clone https://github.com/YC-CLT/cmd-exec-mcp.git
cd cmd-exec-mcp
uv syncMCP 客户端配置
{
"mcpServers": {
"cmd-exec-mcp": {
"command": "uv",
"args": ["run", "--directory", "D:\\your_path\\cmd-exec-mcp", "main.py"]
}
}
}配置
编辑 config.py:
配置 | 默认值 | 说明 |
|
| 安全模式 |
|
| 列表模式: |
|
| 白名单 |
|
| 黑名单 |
|
| 强制指定 Shell: |
|
| WSL 发行版名( |
|
| WSL 用户名( |
|
| 沙箱后端: |
|
| 纯docker沙箱安全模式 |
|
| 纯docker沙箱列表模式 |
|
| 纯docker沙箱黑名单 |
|
| 纯docker沙箱白名单 |
|
| 纯docker沙箱默认镜像 |
|
| 挂载目录( |
|
| 纯docker启动命令前缀(换源等) |
|
| OpenSandbox 模板镜像 |
|
| OpenSandbox 入口脚本 |
|
| OpenSandbox 运行时版本+镜像源 |
|
| OpenSandbox Server 地址 |
|
| OpenSandbox Server 端口 |
|
| OpenSandbox API Key(生产必填) |
|
| Server 配置文件路径,不存在则回退 |
|
| 等待 Server 就绪的最长秒数 |
|
| 空闲超时自动关闭秒数,-1 永不关闭 |
|
| 超时秒数(-1 无限制) |
|
| 输出落盘时 stdout 截断长度 |
|
| 会话默认存活超时秒数,-1 无限 |
|
| 会话最大缓冲行数 |
|
| 会话最大缓冲字节(10 MB) |
|
| 返回字段开关 |
| — | SSH 默认目标 |
|
| SSH 默认用户名 |
|
| SSH 默认端口 |
| — | SSH 密钥路径或密码字符串 |
|
| 跳过 known_hosts 检查 |
|
| SSH 长连接复用 |
|
| SSH 连接超时秒数 |
|
| 日志文件路径 |
|
| 日志级别 |
OpenSandbox 前置条件
如需使用 OpenSandbox 后端 (SANDBOX_BACKEND = "opensandbox"):
前置依赖:Docker Desktop 已安装运行
安装 Server(全局):
uv tool install opensandbox-server部署配置:默认项目
.sandbox.toml,不存在则回退~/.sandbox.toml。在config.py→SANDBOX_CONFIG_PATH里改切换后端:
config.py→SANDBOX_BACKEND = "opensandbox"API Key:本地开发随意,但不建议留空,否则会阻塞让你手动确认;生产环境设
SANDBOX_OPEN_API_KEY
首次调用
execute_sandbox时自动拉起opensandbox-server,空闲SANDBOX_OPEN_SERVER_IDLE_TIMEOUT秒(默认 600)后自动关闭。
SSH 远程执行前置条件
配置
~/.ssh/config的 Host 别名,或在config.py设SSH_DEFAULT_TARGET(格式:[user@]host[:port])或通过环境变量:
SSH_DEFAULT_TARGET、SSH_DEFAULT_USER、SSH_DEFAULT_PORT、SSH_DEFAULT_KEY、SSH_DEFAULT_NO_KNOWN_HOSTS
工具
execute_local
在宿主机执行命令。
{
"command": "echo hello",
"parallel": false,
"timeout": 30,
"cwd": "/tmp",
"env": { "KEY": "value" },
"fields": { "stdout": true, "stderr": false }
}参数 | 类型 | 默认 | 说明 |
| str | 必填 | 命令,并行模式用 |
| str | 必填 | 工作目录 |
| bool | false | 是否并行执行 |
| int | 30 | 超时秒数,-1 无限制 |
| dict | null | 环境变量 |
| dict | null | 返回字段过滤 |
| str | null | 指定 Shell: |
| str | "" | 输出过长时落盘,返回截断预览 |
| bool | false | 后台会话模式 |
| str | null | 会话 ID,用于 read/send/kill |
| str | "send" |
|
| int | 300 | 会话存活超时秒数 |
execute_sandbox
在沙箱中执行命令(Docker/OpenSandbox,由 SANDBOX_BACKEND 决定)。
{
"command": "echo hello",
"parallel": false,
"timeout": 30,
"env": { "KEY": "value" },
"fields": { "stdout": true, "stderr": false }
}参数 | 类型 | 默认 | 说明 |
| str | 必填 | 命令 |
| bool | false | 是否并行 |
| int | 30 | 超时秒数 |
| dict | null | 环境变量 |
| dict | null | 返回字段过滤 |
| str | "" | 输出过长时落盘,返回截断预览 |
| bool | false | 后台会话模式 |
| str | null | 会话 ID,用于 read/send/kill |
| str | "send" |
|
| int | 300 | 会话存活超时秒数 |
execute_remote
通过 SSH 在远程服务器执行命令,配置见 SSH 前置条件。
{
"command": "ls -la",
"parallel": false,
"timeout": 30,
"env": { "KEY": "value" },
"fields": { "stdout": true, "stderr": false }
}参数 | 类型 | 默认 | 说明 |
| str | 必填 | 命令 |
| bool | false | 是否并行 |
| int | 30 | 超时秒数 |
| dict | null | 环境变量 |
| dict | null | 返回字段过滤 |
| str | "" | 输出过长时落盘,返回截断预览 |
| bool | false | 后台会话模式 |
| str | null | 会话 ID,用于 read/send/kill |
| str | "send" |
|
| int | 300 | 会话存活超时秒数 |
会话分离
运行后台长时进程(如开发服务器、REPL)作为会话:
// 启动后台会话
{
"command": "python -m http.server 8080",
"cwd": "/tmp",
"detach": true
}
// 返回: {"session_id": "abc123"}
// 读取输出
{
"session_id": "abc123",
"action": "read"
}
// 发送输入
{
"session_id": "abc123",
"action": "send",
"command": "一些输入\n"
}
// 关闭会话
{
"session_id": "abc123",
"action": "kill"
}会话在 alive_timeout 秒无活动后自动终止(默认 300,-1 无限)。输出缓冲上限为 SESSION_MAX_OUTPUT_BYTES。
测试
uv run pytest tests/ -v非交互执行
非会话模式下 stdin 设为 /dev/null,交互式命令会失败或超时。需要交互式工作流(REPL、Shell 等)用会话分离(见上)。一次性命令请添加对应 flag 跳过提示:
命令 | 参数 | 说明 |
|
| 自动确认 |
|
| 谨慎使用 |
|
| 非交互模式,需要密码则失败 |
| — | 默认非交互 |
| — | 默认黑名单拦截 |
日志
日志写入项目根目录 log.txt,格式:
2026-07-30 12:00:00 [INFO] local: execute: echo hello
2026-07-30 12:00:00 [INFO] local: exit_code=0 duration=0.012协议
MIT
This server cannot be deployed
Maintenance
Related MCP Connectors
MCP server for Superserve sandboxes: create, exec, and manage Firecracker microVMs
Hosted MCP server for task-first delegation to remote workstations and workers.
MCP server for mandates, delegation, policy-gated execution, credential grants, and audit.
MCP Server for an Agent Task Marketplace
Related MCP Servers
AlicenseAqualityFmaintenanceMCP server to give every agent an ephemeral Linux sandboxes for executing shell commands.150MIT- AlicenseBqualityCmaintenanceDynamic MCP server for Node.js enabling runtime tool creation, management, and execution in isolated sandboxes (Docker or Node).811 npm1MIT
- FlicenseAqualityBmaintenanceCross-platform MCP server for policy-controlled command execution on Linux and Windows, with no SSH dependency.3-
- AlicenseNot gradedqualityBmaintenanceMCP server that executes caller-supplied Python code in a network-isolated, locked-down sandbox and returns stdout/stderr/exit code. Supports stdio, HTTP, and SSE transports with optional auth.1MIT