MCP server for sandboxed Python execution. Scripts run in ephemeral, isolated environments with inline dependencies (PEP 723) via uv. Zero host pollution.
- Python 3.13+, no runtime deps beyond
fastmcpandtomli-w uvfor script execution, dependency resolution, and Python version managementhatchlingbuild backend,src/layout
src/mcp_python_exec_sandbox/ # Package source
server.py # FastMCP server + tool definitions
executor.py # uv subprocess orchestration
script.py # PEP 723 metadata parsing/merging
sandbox.py # Sandbox ABC + factory
sandbox_linux.py # bubblewrap sandbox (Linux)
sandbox_docker.py # Docker sandbox (macOS/any)
config.py, cache.py, output.py, errors.py
tests/ # Unit + integration tests (mocked or local uv)
e2e_tests/ # End-to-end tests (require uv + network)
profiles/ # Dockerfile, warmup packages
uv sync --dev # Install deps
uv run pytest tests/ -v # Unit + integration tests
uv run pytest e2e_tests/ -v # E2E tests (slow, needs network)- Run
uv run pytest tests/ -vbefore committing. All tests must pass. - Keep dependencies minimal. Do not add runtime deps without strong justification.
- Lint with
uv run ruff check .and format withuv run ruff format --check .before committing. Fix issues with--fix/ruff format .. - Tool docstrings in
server.pyare user-facing — they become the MCP tool descriptions that agents see. Write them for an LLM audience: include examples, avoid unexplained jargon, link PEPs. - Always pin versions in examples (e.g.
"pandas>=2.2"not"pandas"). - Sandbox backends must degrade gracefully: if the tool (bwrap, docker) is missing, fall back to
NoopSandboxwith a warning. Native sandbox is Linux-only (bwrap); macOS defaults to Docker.
- One logical change per commit. Descriptive commit message (imperative mood).
- Keep PRs focused. Separate refactors from feature work.
- Add tests for new functionality: unit tests in
tests/, E2E ine2e_tests/if it needs real execution. - Update tool docstrings in
server.pyif changing tool behavior. - Update
README.mdif changing user-facing config or adding features.