Sandbox Env MCP

io.github.hs3434由 GitHub 帳號 hs3434 發布v0.3.1更新於 Oct 25, 2026

Persistent Docker/SSH sandbox for AI agents: shell exec, file ops, audit log.

概覽

AI 產生的概覽

為 AI 助理提供持久化 shell 工作階段、檔案操作,以及在沙箱中管理 Docker 或 SSH 機器的能力。

可以做什麼
在持久化的 bash 或 PowerShell shell 中執行指令,讀取緩衝輸出、寫入 stdin 並管理各機器上的 shell 工作階段。在任意目標機器上讀取、寫入、修補和搜尋檔案,寫入為原子操作,並對 JSON、YAML、TOML 做語法檢查。建立、啟動、停止、重新啟動、移除、建置、提交、檢查 Docker 容器並檢視日誌。連線和中斷已設定的 SSH 主機,包括 Windows 目標。當稽核日誌存於 SQLite 時,可查詢歷史工具呼叫紀錄。
適用情境
適合需要真實且有狀態的工作環境而非一次性指令的情境:在多次呼叫之間保留虛擬環境和目錄、同時操作多個容器或遠端主機,或需要為每個操作留下可稽核紀錄。
執行需求
本機 Python 3.12+ 程序,需 Docker SDK 和執行中的 Docker 守護程序;SSH 模式還需 openssh-client。設定位於使用者家目錄下的設定檔,可用環境變數覆寫。HTTP 模式使用權杖檔案中的 bearer 權杖。
安裝前請注意
助理在每台目標機器上擁有完整的檔案系統和 shell 存取權限,對 .ssh、.aws、.env 等敏感路徑的警告僅為提示,不會阻止存取。容器可能以讀寫方式掛載主機工作區目錄,admin 容器可全域檢視所有工作區。Docker 操作會建立、停止和移除容器與映像。SSH 目標及其憑證在設定檔中設定。每次工具呼叫都會被記錄。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Sandbox Env MCP,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

sandbox-mcp

MCP server that gives AI agents a real working environment: persistent shells, a filesystem, and multi-machine management — backed by Docker containers or remote SSH hosts.

Features

  • Persistent shells — stateful bash or PowerShell sessions that survive across tool calls. Set env vars, activate venvs, change directories, and they stay.
  • Multi-machine — manage several Docker containers and SSH hosts simultaneously. Each has its own isolated workspace and shell pool.
  • Full filesystem access — read, write, patch, and search files on any target machine. All writes are atomic (temp-file + rename).
  • Zero-config startup — creates a default Docker container automatically on first run. One command, ready to go.
  • Progressive discovery — env tool exposes capabilities step by step. Agents call env(action="help") to see what's available.
  • Docker lifecycle — create, stop, start, restart, remove containers. Build images, inspect configs, commit state, view logs.
  • SSH remote access — connect to Linux and Windows machines over SSH. Windows targets get automatic code-page probing.
  • Safety net — sensitive-path warnings (.ssh, .aws, .env*) without blocking access. Pre-write syntax lint for JSON/YAML/TOML.
  • Audit trail — every tool call is logged with timestamps, parameters, and outcomes. Queryable from within the agent session.

Quick start

bash
pip install sandbox-env-mcp
# stdio — for Claude Desktop, Cline, Continuesandbox-mcp
# HTTP — for remote agentssandbox-mcp-http

On first run a default container (python:3.14-slim, named admin) starts automatically with a persistent bash shell. No other setup.

Requirements: Python 3.12+, Docker SDK, running Docker daemon. SSH mode needs openssh-client.

Tools

All tools target the default machine unless an explicit machine parameter is passed.

ToolWhat it does
shell_execRun a command in a persistent shell. Blocks until the command finishes (wait=true, 10 s timeout) or fire-and-forget with wait=false.
shell_readRead buffered output from a running or finished command.
shell_newCreate a fresh shell on a machine. Returns a shell_id.
shell_removeTerminate and remove a shell by shell_id.
shell_listList all shells with state, machine, uptime, last command.
write_stdinWrite raw bytes to a running shell — interrupt with Ctrl-C (\x03) or feed input to interactive programs like read / Read-Host. On Windows/PowerShell, Ctrl-C is unsupported (pipe mode has no terminal driver); kill the shell instead.
machine_listList all registered machines with backend, status, purpose, shell count.
default_setSet the default machine or default shell for a machine.
file_readRead a file with line numbers. Supports offset + limit pagination.
file_writeWrite content atomically. Creates parent directories automatically.
file_patchTargeted edits with fuzzy matching. mode=replace (find-and-replace) or mode=patch (unified diff).
file_searchSearch file contents (ripgrep) or find files (glob). Sorted by modification time.
envProgressive-discovery portal. Start with env(action="help").

audit_query is exposed when the audit log is a SQLite database — it lets the agent search historical tool calls.

Shell states

Every shell is in one of four states:

StateWhat it meansWhat the agent can do
initShell just created; booting up. Times out → terminated at 10 s.Wait — shell_exec returns an error until ready.
readyAt a prompt, accepting commands.Send commands, read output, write stdin.
waitingA command is running.Poll output with shell_read. Send Ctrl-C with write_stdin.
terminatedShell process exited (signal, exit, timeout, broken pipe). Last output is preserved.Read remaining output, then shell_remove + shell_new to continue. Default shells are never auto-replaced.

Key shell_exec parameters:

  • wait (default true): block until the command completes.
  • timeout (default 10 s): on expiry returns status="waiting" with a hint to switch to wait=false + shell_read for long-running commands.
  • max_output (default 50000 bytes): caps returned output; excess is shown as the tail (last N bytes).

env actions

env(action="help") lists what's available. env(action="help", topic="<action>") returns full docs for a specific action.

Always available

ActionParamsDescription
helptopic?List actions or get docs for one.
status—Default machine, machines, shells.
list_targets—Pre-defined SSH targets from config.
machine_list—Registered machines.
shell_listmachine?Shells, optionally filtered.
shell_newmachine?, purpose?New shell session.
shell_removeshell_idTerminate and remove.
default_setmachine or shell_idSet default machine or shell.

Docker

ActionRequired paramsDescription
docker_runname, image, purposeCreate/start container. Reattaches on name collision.
docker_ps—List managed containers.
docker_images—List all images on daemon.
docker_image_historyimageLayer-by-layer build history.
docker_buildimage_tag, machineBuild from a Dockerfile in /workspace.
docker_commitmachine, image_tagCommit container as new image.
docker_stopmachineStop (state preserved).
docker_startmachineStart a stopped container.
docker_removemachineStop + remove container and its shells.
docker_inspectmachineCurated config. kind=image for images.
docker_logsmachineLogs with tail, since, until.
docker_diffmachineFilesystem changes vs image.
docker_statsmachineCPU/memory/network/IO snapshot.
docker_restartmachineStop + start + verify.

SSH

ActionRequired paramsDescription
connectnameConnect to a configured target.
closenameDisconnect and unregister.

Available when [ssh.targets] is configured.

File operations

ToolKey paramsHighlights
file_readpath, offset, limitLine-numbered. Rejects files > 50 KB with a hint.
file_writepath, contentAtomic (temp + rename), auto-creates parent dirs, post-write verification.
file_patchpath, old_string, new_string (replace mode) or patch (unified diff)Fuzzy matching. Preserves BOM and line endings.
file_searchpattern, search_type, path, file_glob, limitPowered by ripgrep. Results sorted by modification time.

Safety warnings are surfaced for sensitive paths (.ssh, .aws, .env*, /etc/shadow, etc.) — advisory only, agents still have full access. Writes to .json, .yaml, .yml, .toml are syntax-checked before writing (fail-closed).

Configuration

Config lives at ~/.sandbox-mcp/config.toml (copy config/config.example.toml). Every field can be overridden with SANDBOX_MCP_<SECTION>_<KEY> env vars.

toml
[server]port = 8010auth_tokens_file = "~/.sandbox-mcp/auth_tokens"
[storage]work_home = "/var/lib/sandbox-mcp"
[docker]default_image = "python:3.14-slim"auto_network = "sandbox-mcp"      # "" = noneadmin_machine = "admin"           # "" = no /host mounthost = ""                         # "" = from Docker environment
[ssh]connect_timeout = 10[ssh.targets.win-build]host = "192.168.1.100"user = "builder"os_type = "windows"
[default_machine]enabled = truebackend = "docker"name = "admin"
[shell]default_max_output = 50000
[files]max_file_size = 51200

Backends

Docker

Containers get bind mounts for workspace isolation:

  • work_home/<name>/ → /workspace (rw)
  • work_home/<share_subdir>/ → /share/ (ro, shared across peers)
  • work_home/<share_subdir>/<name>/ → /share/<name>/ (rw overlay)

When a container's name matches admin_machine, it also gets work_home/ → /host (rw) — a global view of all workspaces.

Server startup auto-reconciles with the Docker daemon: surviving containers are re-adopted into the registry.

SSH

Connects over SSH with ControlMaster for connection reuse. Windows targets get automatic code-page probing and encoded-command execution.

Deployment

yaml
# docker-compose.ymlservices:  sandbox-mcp:    image: ghcr.io/hs3434/sandbox-env-mcp:latest    network_mode: host    volumes:      - /var/run/docker.sock:/var/run/docker.sock      - /var/lib/sandbox-mcp:/var/lib/sandbox-mcp      - ./config:/root/.sandbox-mcp

HTTP mode reads bearer tokens from auth_tokens_file (hot-reload on every request). If the file is empty or missing and auto_generate_if_empty=true, a random token is printed to stderr at startup.

Audit

Every tool call is recorded: timestamp, machine, action, status, duration, and hashed parameters. Defaults to SQLite at ~/.sandbox-mcp/audit.db. Set log_path="" for JSON-line stderr output instead.

來源:README.md,提交 939e52c

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v0.3.1最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分