
Python Exec Sandbox
io.github.lu-zhengda由 GitHub 帳號 lu-zhengda 發布v0.1.5更新於 Oct 25, 2026
Sandboxed Python execution for AI agents. PEP 723 inline deps, multi-version Python, zero pollution.
概覽
本機 MCP 伺服器,讓 AI 助理在隔離沙箱中執行 Python 腳本,支援 PEP 723 內嵌相依套件與可選的 Python 版本。
- 可以做什麼
- 執行 Python 腳本,自動解析相依套件,可附加額外相依宣告並設定單次執行逾時,輸出會被截斷以免淹沒助理的上下文。在不執行的情況下驗證腳本的 PEP 723 中繼資料與相依套件。檢視執行環境資訊,包括 Python 與 uv 版本、平台、沙箱狀態與設定。可在 Python 3.13、3.14 或 3.15 上執行腳本,由 uv 自動下載目標版本。
- 適用情境
- 適合助理需要執行 Python 做計算、資料檢查或快速實驗,又不希望污染本機 Python、site-packages 或虛擬環境的情況。也適合需要每次執行隔離、環境用完即丟與可控逾時的工作流程。
- 執行需求
- 以 stdio 在本機執行,通常透過 uvx 啟動。伺服器程序需要 Python 3.13+,相依解析與 Python 版本下載需要 uv。沙箱在 Linux 上需要 bubblewrap,在 macOS 及其他平台需要 Docker;Docker 映像首次使用時會自動拉取。無沙箱後端則兩者都不需要。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Python Exec Sandbox,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
mcp-python-exec-sandbox
[CI] [PyPI] [Python] [License]
Sandboxed Python execution for AI agents. Scripts run in ephemeral, isolated environments with inline dependencies (PEP 723) -- zero host pollution, zero leftover venvs, zero package conflicts.
Why?
Every coding agent can already run Python on your host. The problem is what happens next: packages accumulate, venvs sprawl, and a rogue pip install breaks your system. mcp-python-exec-sandbox eliminates this:
- Scripts execute in a sandbox (bubblewrap on Linux, Docker on macOS/other platforms)
- Dependencies are declared inline and resolved ephemerally via
uv - Nothing touches your host's Python, site-packages, or virtualenvs
- Each execution is isolated and disposable
Features
- Sandboxed execution -- platform-specific isolation prevents host filesystem access
- PEP 723 inline metadata -- declare dependencies directly in scripts with
# /// scriptblocks - Multi-version Python -- run scripts on Python 3.13, 3.14, or 3.15 (uv downloads the right version automatically)
- Ephemeral environments -- dependencies are resolved per-execution, never persisted
- Package caching -- uv's global cache makes repeat installs near-instant
- Timeout enforcement -- configurable per-execution timeouts
- Output truncation -- prevents runaway output from overwhelming the agent
Prerequisites
All setups require:
- Python 3.13+ -- to run the MCP server process
- uv -- manages script execution, dependency resolution, and Python version downloads. Also provides
uvxfor running the server without installing it globally.
Additional requirements depend on your chosen sandbox backend:
Host Python vs. execution Python: These are independent. Python 3.13+ is needed to run the server process itself. The
--python-versionflag controls which Python version your scripts execute on -- uv downloads the target version automatically. You do not need to install Python 3.14 or 3.15 on your host to run scripts on those versions.
Quick start
Claude Code (Linux -- native sandbox)
Claude Code (macOS -- Docker sandbox, recommended)
The Docker sandbox image is pulled automatically from GHCR on first use. No manual build required.
Claude Code (no sandbox)
Cursor
Add to .cursor/mcp.json (project-level) or ~/.cursor/mcp.json (global):
OpenAI Codex CLI
Or add to .codex/config.toml:
Other MCP clients
Any client that supports the MCP stdio transport can use this server:
Multi-version Python
Use --python-version to target a specific Python version. uv downloads it automatically -- no manual install needed.
This works across all sandbox backends. The Docker sandbox uses uv inside the container to manage Python versions, so the same --python-version flag applies.
Tools
execute_python
Execute a Python script with automatic dependency management.
check_environment
Returns information about the execution environment: Python version, uv version, platform, sandbox status, and configuration.
validate_script
Validates a script's PEP 723 metadata and dependencies without executing it.
Sandbox backends
The default backend is native (bubblewrap) on Linux and docker on macOS/other platforms. Specifying --sandbox-backend native on macOS automatically redirects to Docker. If the sandbox tool is unavailable, the server falls back to none with a warning.
Docker sandbox setup
The Docker sandbox image is published to GHCR and pulled automatically when the server starts. No manual setup is needed.
To build locally for development:
CLI options
Development
Setup
Project structure
Running tests
Unit and integration tests -- fast, run everywhere:
E2E tests -- require uv and network access. These exercise real script execution, package installation, MCP protocol flow, and sandbox enforcement:
Docker sandbox tests
The Docker E2E tests (e2e_tests/test_docker_sandbox.py) verify execution, dependency installation, read-only filesystem enforcement, host isolation, and timeout handling through the Docker backend.
Prerequisites:
- Docker must be installed and running
- Build the sandbox image:
Then run:
These tests are automatically skipped if Docker is unavailable or the image hasn't been built.
Linux sandbox tests (devcontainer)
The Linux sandbox tests (e2e_tests/test_sandbox_enforcement.py::test_linux_sandbox_blocks_etc_shadow) use bubblewrap (bwrap) for namespace isolation. They are skipped on macOS because bwrap is Linux-only.
To run them from macOS, use the included devcontainer which provides Ubuntu 24.04 with bwrap pre-installed:
VS Code:
- Install the Dev Containers extension
- Open the project and select Reopen in Container
- In the integrated terminal:
CLI:
Test matrix
Contributing
- One logical change per commit. Descriptive commit message (imperative mood).
- Run
uv run pytest tests/ -vbefore committing -- all tests must pass. - Add tests for new functionality: unit tests in
tests/, E2E ine2e_tests/if it needs real execution. - Keep dependencies minimal. Do not add runtime deps without strong justification.
- Tool docstrings in
server.pyare user-facing MCP tool descriptions. Write them for an LLM audience. - Sandbox backends must degrade gracefully: if the required tool (bwrap, docker) is missing, fall back to
NoopSandboxwith a warning.
License
MIT
來源:README.md,提交 ffdee0e
工具
0版本歷史
1- v0.1.5最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分