mcp-python-exec-sandbox 0.1.1__tar.gz → 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. mcp_python_exec_sandbox-0.1.2/PKG-INFO +307 -0
  2. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/pyproject.toml +18 -1
  3. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/uv.lock +1 -1
  4. mcp_python_exec_sandbox-0.1.1/PKG-INFO +0 -9
  5. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/.devcontainer/Dockerfile +0 -0
  6. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/.devcontainer/devcontainer.json +0 -0
  7. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/.github/workflows/ci.yml +0 -0
  8. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/.gitignore +0 -0
  9. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/CLAUDE.md +0 -0
  10. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/LICENSE +0 -0
  11. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/README.md +0 -0
  12. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/e2e_tests/__init__.py +0 -0
  13. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/e2e_tests/test_data_science.py +0 -0
  14. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/e2e_tests/test_docker_sandbox.py +0 -0
  15. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/e2e_tests/test_mcp_protocol.py +0 -0
  16. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/e2e_tests/test_package_install.py +0 -0
  17. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/e2e_tests/test_real_execution.py +0 -0
  18. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/e2e_tests/test_sandbox_enforcement.py +0 -0
  19. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/profiles/Dockerfile +0 -0
  20. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/profiles/sandbox_macos.sb +0 -0
  21. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/profiles/warmup_packages.txt +0 -0
  22. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/src/mcp_python_exec_sandbox/__init__.py +0 -0
  23. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/src/mcp_python_exec_sandbox/__main__.py +0 -0
  24. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/src/mcp_python_exec_sandbox/cache.py +0 -0
  25. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/src/mcp_python_exec_sandbox/config.py +0 -0
  26. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/src/mcp_python_exec_sandbox/errors.py +0 -0
  27. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/src/mcp_python_exec_sandbox/executor.py +0 -0
  28. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/src/mcp_python_exec_sandbox/output.py +0 -0
  29. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/src/mcp_python_exec_sandbox/sandbox.py +0 -0
  30. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/src/mcp_python_exec_sandbox/sandbox_docker.py +0 -0
  31. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/src/mcp_python_exec_sandbox/sandbox_linux.py +0 -0
  32. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/src/mcp_python_exec_sandbox/sandbox_macos.py +0 -0
  33. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/src/mcp_python_exec_sandbox/script.py +0 -0
  34. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/src/mcp_python_exec_sandbox/server.py +0 -0
  35. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/tests/__init__.py +0 -0
  36. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/tests/conftest.py +0 -0
  37. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/tests/test_config.py +0 -0
  38. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/tests/test_executor.py +0 -0
  39. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/tests/test_integration.py +0 -0
  40. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/tests/test_output.py +0 -0
  41. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/tests/test_sandbox.py +0 -0
  42. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/tests/test_script.py +0 -0
  43. {mcp_python_exec_sandbox-0.1.1 → mcp_python_exec_sandbox-0.1.2}/tests/test_server.py +0 -0
@@ -0,0 +1,307 @@
1
+ Metadata-Version: 2.4
2
+ Name: mcp-python-exec-sandbox
3
+ Version: 0.1.2
4
+ Summary: MCP server for secure Python script execution with automatic dependency management
5
+ Project-URL: Homepage, https://github.com/lu-zhengda/mcp-python-exec-sandbox
6
+ Project-URL: Repository, https://github.com/lu-zhengda/mcp-python-exec-sandbox
7
+ Project-URL: Issues, https://github.com/lu-zhengda/mcp-python-exec-sandbox/issues
8
+ Author: Zhengda Lu
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: agent,ai,execution,mcp,python,sandbox
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Security
18
+ Classifier: Topic :: Software Development :: Interpreters
19
+ Requires-Python: >=3.13
20
+ Requires-Dist: fastmcp<3,>=2.0
21
+ Requires-Dist: tomli-w>=1.0
22
+ Description-Content-Type: text/markdown
23
+
24
+ # mcp-python-exec-sandbox
25
+
26
+ Sandboxed Python execution for AI agents. Scripts run in ephemeral, isolated environments with inline dependencies ([PEP 723](https://peps.python.org/pep-0723/)) -- **zero host pollution, zero leftover venvs, zero package conflicts**.
27
+
28
+ ## Why?
29
+
30
+ 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:
31
+
32
+ - Scripts execute in a sandbox (bubblewrap on Linux, sandbox-exec on macOS, Docker everywhere)
33
+ - Dependencies are declared inline and resolved ephemerally via `uv`
34
+ - Nothing touches your host's Python, site-packages, or virtualenvs
35
+ - Each execution is isolated and disposable
36
+
37
+ ## Features
38
+
39
+ - **Sandboxed execution** -- platform-specific isolation prevents host filesystem access
40
+ - **PEP 723 inline metadata** -- declare dependencies directly in scripts with `# /// script` blocks
41
+ - **Multi-version Python** -- run scripts on Python 3.13, 3.14, or 3.15 (uv downloads the right version automatically)
42
+ - **Ephemeral environments** -- dependencies are resolved per-execution, never persisted
43
+ - **Package caching** -- uv's global cache makes repeat installs near-instant
44
+ - **Timeout enforcement** -- configurable per-execution timeouts
45
+ - **Output truncation** -- prevents runaway output from overwhelming the agent
46
+
47
+ ## Prerequisites
48
+
49
+ All setups require:
50
+
51
+ - **Python 3.13+** -- to run the MCP server process
52
+ - **[uv](https://docs.astral.sh/uv/getting-started/installation/)** -- manages script execution, dependency resolution, and Python version downloads. Also provides `uvx` for running the server without installing it globally.
53
+
54
+ Additional requirements depend on your chosen sandbox backend:
55
+
56
+ | Setup | Additional requirements | Install |
57
+ |-------|------------------------|---------|
58
+ | **Native sandbox (Linux)** | [bubblewrap](https://github.com/containers/bubblewrap) | `sudo apt install bubblewrap` |
59
+ | **Native sandbox (macOS)** | None -- `sandbox-exec` is built into macOS | -- |
60
+ | **Docker sandbox** | [Docker Engine](https://docs.docker.com/engine/install/) | See Docker docs |
61
+ | **No sandbox** | None | -- |
62
+
63
+ > **Host Python vs. execution Python:** These are independent. Python 3.13+ is needed to run the server process itself. The `--python-version` flag 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.
64
+
65
+ ## Quick start
66
+
67
+ ### Claude Code (native sandbox -- recommended)
68
+
69
+ ```bash
70
+ claude mcp add python-sandbox -- uvx mcp-python-exec-sandbox --sandbox-backend native
71
+ ```
72
+
73
+ ### Claude Code (Docker sandbox)
74
+
75
+ ```bash
76
+ docker build -t mcp-python-exec-sandbox profiles/
77
+ claude mcp add python-sandbox -- uvx mcp-python-exec-sandbox --sandbox-backend docker
78
+ ```
79
+
80
+ > The Docker image build requires the repo source. Clone it first: `git clone https://github.com/lu-zhengda/mcp-python-exec-sandbox.git`
81
+
82
+ ### Claude Code (no sandbox)
83
+
84
+ ```bash
85
+ claude mcp add python-sandbox -- uvx mcp-python-exec-sandbox --sandbox-backend none
86
+ ```
87
+
88
+ ### Manual JSON config
89
+
90
+ ```json
91
+ {
92
+ "mcpServers": {
93
+ "python-sandbox": {
94
+ "command": "uvx",
95
+ "args": ["mcp-python-exec-sandbox", "--sandbox-backend", "native"]
96
+ }
97
+ }
98
+ }
99
+ ```
100
+
101
+ ## Multi-version Python
102
+
103
+ Use `--python-version` to target a specific Python version. uv downloads it automatically -- no manual install needed.
104
+
105
+ ```bash
106
+ # Python 3.13 (default)
107
+ uvx mcp-python-exec-sandbox --python-version 3.13
108
+
109
+ # Python 3.14
110
+ uvx mcp-python-exec-sandbox --python-version 3.14
111
+
112
+ # Python 3.15
113
+ uvx mcp-python-exec-sandbox --python-version 3.15
114
+ ```
115
+
116
+ 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.
117
+
118
+ ## Tools
119
+
120
+ ### `execute_python`
121
+
122
+ Execute a Python script with automatic dependency management.
123
+
124
+ | Parameter | Type | Default | Description |
125
+ |-----------|------|---------|-------------|
126
+ | `script` | str | required | Python source code, may include PEP 723 inline metadata |
127
+ | `dependencies` | list[str] | `[]` | Extra PEP 508 dependency specifiers to merge |
128
+ | `timeout_seconds` | int | 30 | Maximum execution time (1--300) |
129
+
130
+ ```python
131
+ # Simple script
132
+ execute_python(script="print('hello world')")
133
+
134
+ # Script with dependencies
135
+ execute_python(
136
+ script="import requests; print(requests.get('https://httpbin.org/get').status_code)",
137
+ dependencies=["requests"]
138
+ )
139
+
140
+ # Script with inline PEP 723 metadata
141
+ execute_python(script="""
142
+ # /// script
143
+ # dependencies = ["pandas", "matplotlib"]
144
+ # ///
145
+
146
+ import pandas as pd
147
+ print(pd.DataFrame({'a': [1,2,3]}).describe())
148
+ """)
149
+ ```
150
+
151
+ ### `check_environment`
152
+
153
+ Returns information about the execution environment: Python version, uv version, platform, sandbox status, and configuration.
154
+
155
+ ### `validate_script`
156
+
157
+ Validates a script's PEP 723 metadata and dependencies without executing it.
158
+
159
+ | Parameter | Type | Default | Description |
160
+ |-----------|------|---------|-------------|
161
+ | `script` | str | required | Python source code to validate |
162
+ | `dependencies` | list[str] | `[]` | Extra dependency specifiers to validate |
163
+
164
+ ## Sandbox backends
165
+
166
+ | Backend | Platform | Tool | Notes |
167
+ |---------|----------|------|-------|
168
+ | `native` | Linux | bubblewrap | Namespace isolation, network allowed |
169
+ | `native` | macOS | sandbox-exec | Seatbelt profiles, network allowed |
170
+ | `docker` | Any | Docker | Container isolation, resource limits |
171
+ | `none` | Any | -- | No sandboxing (not recommended) |
172
+
173
+ If the requested sandbox tool is unavailable, the server falls back to `none` with a warning.
174
+
175
+ ### Docker sandbox setup
176
+
177
+ ```bash
178
+ docker build -t mcp-python-exec-sandbox profiles/
179
+ ```
180
+
181
+ ## CLI options
182
+
183
+ ```
184
+ mcp-python-exec-sandbox [OPTIONS]
185
+
186
+ Options:
187
+ --python-version TEXT Python version for execution (default: 3.13)
188
+ --sandbox-backend TEXT native | docker | none (default: native)
189
+ --max-timeout INT Maximum allowed timeout in seconds (default: 300)
190
+ --default-timeout INT Default timeout in seconds (default: 30)
191
+ --max-output-bytes INT Maximum output size in bytes (default: 102400)
192
+ --no-warm-cache Skip cache warming on startup
193
+ --uv-path TEXT Path to uv binary (default: uv)
194
+ ```
195
+
196
+ ## Development
197
+
198
+ ### Setup
199
+
200
+ ```bash
201
+ git clone https://github.com/lu-zhengda/mcp-python-exec-sandbox.git
202
+ cd mcp-python-exec-sandbox
203
+ uv sync --dev
204
+ ```
205
+
206
+ ### Project structure
207
+
208
+ ```
209
+ src/mcp_python_exec_sandbox/ # Package source
210
+ server.py # FastMCP server + tool definitions
211
+ executor.py # uv subprocess orchestration
212
+ script.py # PEP 723 metadata parsing/merging
213
+ sandbox.py # Sandbox ABC + factory
214
+ sandbox_{linux,macos,docker}.py
215
+ config.py, cache.py, output.py, errors.py
216
+ tests/ # Unit + integration tests (mocked or local uv)
217
+ e2e_tests/ # End-to-end tests (require uv + network)
218
+ profiles/ # Dockerfile, macOS seatbelt profile, warmup packages
219
+ .devcontainer/ # Devcontainer for Linux sandbox testing from macOS
220
+ ```
221
+
222
+ ### Running tests
223
+
224
+ **Unit and integration tests** -- fast, run everywhere:
225
+
226
+ ```bash
227
+ uv run pytest tests/ -v
228
+ ```
229
+
230
+ **E2E tests** -- require `uv` and network access. These exercise real script execution, package installation, MCP protocol flow, and sandbox enforcement:
231
+
232
+ ```bash
233
+ uv run pytest e2e_tests/ -v
234
+ ```
235
+
236
+ ### Docker sandbox tests
237
+
238
+ 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.
239
+
240
+ Prerequisites:
241
+
242
+ 1. Docker must be installed and running
243
+ 2. Build the sandbox image:
244
+
245
+ ```bash
246
+ docker build -t mcp-python-exec-sandbox profiles/
247
+ ```
248
+
249
+ Then run:
250
+
251
+ ```bash
252
+ uv run pytest e2e_tests/test_docker_sandbox.py -v
253
+ ```
254
+
255
+ These tests are automatically skipped if Docker is unavailable or the image hasn't been built.
256
+
257
+ ### Linux sandbox tests (devcontainer)
258
+
259
+ 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.
260
+
261
+ To run them from macOS, use the included devcontainer which provides Ubuntu 24.04 with `bwrap` pre-installed:
262
+
263
+ **VS Code:**
264
+
265
+ 1. Install the [Dev Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension
266
+ 2. Open the project and select **Reopen in Container**
267
+ 3. In the integrated terminal:
268
+
269
+ ```bash
270
+ uv run pytest e2e_tests/test_sandbox_enforcement.py -v
271
+ ```
272
+
273
+ **CLI:**
274
+
275
+ ```bash
276
+ # Install the devcontainer CLI (once)
277
+ npm install -g @devcontainers/cli
278
+
279
+ # Build and start the container
280
+ devcontainer up --workspace-folder .
281
+
282
+ # Run the Linux sandbox tests inside the container
283
+ devcontainer exec --workspace-folder . uv run pytest e2e_tests/test_sandbox_enforcement.py -v
284
+ ```
285
+
286
+ ### Test matrix
287
+
288
+ | Test suite | Command | Requirements |
289
+ |------------|---------|-------------|
290
+ | Unit tests | `uv run pytest tests/ -v` | `uv` |
291
+ | Integration tests | `uv run pytest tests/test_integration.py -v` | `uv` |
292
+ | E2E (general) | `uv run pytest e2e_tests/ -v` | `uv`, network |
293
+ | E2E (Docker sandbox) | `uv run pytest e2e_tests/test_docker_sandbox.py -v` | `uv`, Docker, sandbox image |
294
+ | E2E (Linux/bwrap sandbox) | `uv run pytest e2e_tests/test_sandbox_enforcement.py -v` | `uv`, Linux with `bwrap` (or devcontainer) |
295
+
296
+ ### Contributing
297
+
298
+ - One logical change per commit. Descriptive commit message (imperative mood).
299
+ - Run `uv run pytest tests/ -v` before committing -- all tests must pass.
300
+ - Add tests for new functionality: unit tests in `tests/`, E2E in `e2e_tests/` if it needs real execution.
301
+ - Keep dependencies minimal. Do not add runtime deps without strong justification.
302
+ - Tool docstrings in `server.py` are user-facing MCP tool descriptions. Write them for an LLM audience.
303
+ - Sandbox backends must degrade gracefully: if the tool is missing, fall back to `NoopSandbox` with a warning.
304
+
305
+ ## License
306
+
307
+ MIT
@@ -1,11 +1,28 @@
1
1
  [project]
2
2
  name = "mcp-python-exec-sandbox"
3
- version = "0.1.1"
3
+ version = "0.1.2"
4
4
  description = "MCP server for secure Python script execution with automatic dependency management"
5
+ readme = "README.md"
5
6
  requires-python = ">=3.13"
6
7
  license = "MIT"
8
+ authors = [{ name = "Zhengda Lu" }]
9
+ keywords = ["mcp", "sandbox", "python", "execution", "ai", "agent"]
10
+ classifiers = [
11
+ "Development Status :: 4 - Beta",
12
+ "Intended Audience :: Developers",
13
+ "License :: OSI Approved :: MIT License",
14
+ "Programming Language :: Python :: 3",
15
+ "Programming Language :: Python :: 3.13",
16
+ "Topic :: Software Development :: Interpreters",
17
+ "Topic :: Security",
18
+ ]
7
19
  dependencies = ["fastmcp>=2.0,<3", "tomli-w>=1.0"]
8
20
 
21
+ [project.urls]
22
+ Homepage = "https://github.com/lu-zhengda/mcp-python-exec-sandbox"
23
+ Repository = "https://github.com/lu-zhengda/mcp-python-exec-sandbox"
24
+ Issues = "https://github.com/lu-zhengda/mcp-python-exec-sandbox/issues"
25
+
9
26
  [project.scripts]
10
27
  mcp-python-exec-sandbox = "mcp_python_exec_sandbox.__main__:main"
11
28
 
@@ -639,7 +639,7 @@ wheels = [
639
639
 
640
640
  [[package]]
641
641
  name = "mcp-python-exec-sandbox"
642
- version = "0.1.0"
642
+ version = "0.1.2"
643
643
  source = { editable = "." }
644
644
  dependencies = [
645
645
  { name = "fastmcp" },
@@ -1,9 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: mcp-python-exec-sandbox
3
- Version: 0.1.1
4
- Summary: MCP server for secure Python script execution with automatic dependency management
5
- License-Expression: MIT
6
- License-File: LICENSE
7
- Requires-Python: >=3.13
8
- Requires-Dist: fastmcp<3,>=2.0
9
- Requires-Dist: tomli-w>=1.0