Win-wrap MCP Server
by you536GHT233
README.md
[English](README.md) | [Arabic version](README.ar.md) · [Usage Manual](USAGE.md) · [MCP & Multi-Language Hooks](INTEGRATION_HOOKS_WIN.md) · [Technical Architecture](WIN_SANDBOX.md) · [Security Policy](SECURITY.md)
# Win-wrap (`wwrap`) v0.1.1
### Run Windows executables, Python scripts, and AI agent tools with bounded user-mode permissions — zero external dependencies, no Docker, no VM, and no Administrator rights.
Inspired by Linux [`bubblewrap` (`bwrap`)](https://github.com/containers/bubblewrap), **`Win-wrap`** confines child processes on **Windows 10 and Windows 11 (x64)** using only Python's standard library (`>= 3.10`) and built-in Windows kernel controls (AppContainer, scoped NTFS permissions, and Job Objects).
---
## Contents
- [Choose Your Mode](#choose-your-mode)
- [How Win-wrap Fits on Windows](#how-win-wrap-fits-on-windows)
- [Install](#install)
- [Quick Start](#quick-start)
- [Use Cases](#use-cases)
- [How Isolation Works](#how-isolation-works)
- [Testing on Windows 10 and 11](#testing-on-windows-10-and-11)
- [Roadmap](#roadmap)
- [Documentation Map](#documentation-map)
---
## Choose Your Mode
| Goal | Integration Mode | Entry Point | End-User Needs Python? |
| :--- | :--- | :--- | :---: |
| Confine `.exe` tools, scripts, or CI steps from terminal | **1. Standalone CLI** | `wwrap --bind C:\out -- cmd.exe /c ...` | Yes (host running CLI) |
| Run plugins, evaluators, or graders from Python code | **2. Python Library** | `from win_wrap import run_python_windows` | Yes (host app env) |
| Give AI agents bounded Python/process execution | **3. Built-in MCP Server** | `wwrap --mcp --bind C:\scratch` | Yes (or via `wwrap.exe`) |
| Bundle Windows confinement into C#, Rust, Go, C++, or Node.js apps | **4. Standalone `wwrap.exe`** | Download from GitHub Releases (or build once) | **No — zero Python needed** |
---
## How Win-wrap Fits on Windows
- **Pure Python Stdlib, Zero Dependencies**: Runs directly on Windows `ctypes` (`kernel32`, `advapi32`, `userenv`) with zero third-party packages, no Docker daemon, no Hyper-V/WSL2 VM, and no separate runtime service.
- **Windows 10 & 11 (`x64`) Without Administrator Setup**: Works out of the box under standard non-admin user accounts (no UAC elevation required), automatically mirroring read-only Python runtimes when `C:\Python*` lacks non-admin ACL edit rights.
- **Built-in AI Agent MCP Server (`--mcp`)**: Ships a ready-to-use stdio JSON-RPC 2.0 server with default-deny directory rules and operator-enforced memory/time/process ceilings.
- **Standalone Zero-Python `wwrap.exe`**: Freezes cleanly into a portable `--onedir` (`~17.2 MiB`, `53` files, `~140 ms` warm latency from a Python-less `.NET 10` host) or Nuitka `--standalone` executable bundle for C#, Rust, Go, C++, Node.js, and Electron host apps.
---
## Install
- **Python CLI & Library** (`Python 3.10–3.15` on Windows 10/11 x64):
```powershell
pip install .
```
- **Portable Mode (Zero Install)**: Set `$env:PYTHONPATH = "lib"` and run `python -m win_wrap ...` directly without global installation.
- **Zero-Python Standalone Binary (`wwrap.exe`)**: Download the prebuilt `wwrap.exe` bundle from **GitHub Releases** (or freeze [lib/win_sandbox.py](lib/win_sandbox.py) once on a build machine with `pyinstaller --onedir --clean --name wwrap lib/win_sandbox.py` or Nuitka `--standalone` for fast startup — `--onedir` avoids `--onefile`'s per-run `%TEMP%` extraction overhead; see [USAGE.md](USAGE.md)).
---
## Quick Start
### 1. Terminal CLI (`wwrap`)
```powershell
# Read C:\work\input (read-only), write ONLY to C:\work\scratch, 512 MB RAM, 10s limit
wwrap --ro-bind C:\work\input --bind C:\work\scratch --cwd C:\work\scratch --mem 512 --timeout 10 -- python C:\work\input\script.py
# Disposable one-shot container (--isolate-session) deleted immediately after exit
win-wrap --isolate-session --bind C:\work\out --cwd C:\work\out --mem 256 --timeout 5 -- cmd.exe /c "echo done > out.txt"
```
### 2. Python Library (`import win_wrap`)
```python
from win_wrap import run_python_windows, run_process_windows
# Run Python code via stdin (source stays in memory)
stdout, stderr, rc = run_python_windows(
"import os; print('isolated pid:', os.getpid())",
timeout=15,
memory_limit_mb=512,
max_processes=2,
)
# Run any Windows executable in a disposable one-shot AppContainer
stdout, stderr, rc = run_process_windows(
["cmd.exe", "/c", "ver"],
timeout=10,
memory_limit_mb=256,
max_processes=1,
isolate_session=True,
)
```
> [!NOTE]
> When wrapping a Python virtual environment (`venv\Scripts\python.exe`), set `max_processes >= 2` (`--max-procs 2`) because the Windows `venv` launcher spawns the base interpreter as a child process (`max_processes=1` returns exit code `101`).
### 3. Built-in AI Agent MCP Server (`--mcp`)
```powershell
wwrap --mcp --ro-bind C:\work\input --bind C:\work\scratch --cwd C:\work\scratch --mem 512 --timeout 30 --max-procs 2
```
Exposes `run_sandboxed_python`, `run_sandboxed_process`, and `get_sandbox_policy` over stdio JSON-RPC 2.0 while enforcing operator directory allowlists and resource ceilings (pass `--isolate-session` for strict per-call ACL isolation; when running frozen `wwrap.exe --mcp`, pass `--python <path>` to enable `run_sandboxed_python`). See [INTEGRATION_HOOKS_WIN.md](INTEGRATION_HOOKS_WIN.md) for copy-paste **Claude Desktop**, **Cursor**, **VS Code**, **Windsurf**, and **Antigravity** configurations plus C#/Rust/Go/C++/Node.js examples for `wwrap.exe`.
---
## Use Cases
- **AI Agents & MCP Hosts (`wwrap --mcp`)**: confine LLM-generated scripts and commands with operator-enforced folder rules and hard memory/time caps (`25.72 calls/s` on Win11; `11.05–16.31 calls/s` on Win10). For repeated runs, keep a persistent `--mcp` or Python host process alive instead of spawning a fresh CLI process per call.
- **Bundling Inside Non-Python Apps (`wwrap.exe`)**: ship a standalone `--onedir` or Nuitka bundle with C#, Rust, Go, C++, Node.js, or Electron desktop apps without requiring Python on customer machines.
- **Python Plugins & Automated Graders (`import win_wrap`)**: isolate evaluator scripts and data processors inline (`~10–13 ms` warm shared overhead on Win11; pre-warmed `isolate_session` pool for fast disposable runs).
- **Terminal, Automation & CI (`wwrap` / `win-wrap`)**: wrap compilers, formatters, archives, or CLI utilities cleanly under standard user accounts.
- **Isolated Inspection of Unfamiliar Scripts**: inspect or run unfamiliar scripts with bounded user-mode filesystem permissions, no network access (AppContainer), and strict resource/time caps (see [SECURITY.md](SECURITY.md) for threat-model boundaries).
---
## How Isolation Works
Unlike Linux `bubblewrap` (which uses POSIX namespaces), **`Win-wrap`** maps practical workflow isolation directly onto standard Windows kernel mechanisms:
1. **No Network by Default**: Launches inside a zero-capability Windows **AppContainer**, causing the kernel and Windows Filtering Platform (WFP) to block outbound, LAN, and loopback sockets.
2. **Bounded Filesystem & Registry**: Denies `%USERPROFILE%`, drive roots, system paths, UNC paths, and symlinks; grants read (`--ro-bind`) or write (`--bind`) only on explicitly requested folders, with automatic user-owned runtime mirroring when host Python installs under `C:\` lack non-admin ACL edit rights. Registry writes stay isolated to the container's virtual hive.
3. **Resource & Tree Limits**: Binds suspended processes to a **Job Object** before resuming execution, capping committed RAM (`--mem`), concurrent processes (`--max-procs`), and wall-clock/CPU time (`--timeout`) with deterministic tree termination on exit or timeout.
4. **UI & Handle Isolation**: Restricts inherited handles to only the 3 stdio pipes and blocks desktop/clipboard/window message access (interactive GUI tools and profile/UI/WMI-dependent PowerShell commands are unsupported and may fail under `0xFF`, especially on Windows 10, even when simple non-interactive commands like `powershell.exe -NoProfile` succeed on newer Windows 11 builds; standard console binaries work reliably).
For full Win32 struct layouts, ACL bitmasks (`0xFF`, `0x001200A9`, `0x001301FF`), SID mechanics, `py_mirror` details, and full 8-environment Windows 11 (`3.13.15`) + Windows 10 (`3.10.11–3.15.2`) multi-binary benchmarks, see **[WIN_SANDBOX.md](WIN_SANDBOX.md)** and **[SECURITY.md](SECURITY.md)**.
---
## Testing on Windows 10 and 11
> [!IMPORTANT]
> The test suite runner is **`python tests/test_win_sandbox.py`** (or `python -B tests/test_win_sandbox.py`), **not `unittest discover`**, and **requires Windows 10 or Windows 11 (x64)**. When invoked on Linux or macOS, both `tests/test_win_sandbox.py` and `run_win_sandbox_check.py` detect `sys.platform != "win32"`, print a `SKIP` notice, and exit cleanly with code `0`.
```powershell
# Standalone self-test suite (196 checks: ABI/mocked kernel + live OS confinement & MCP)
python -B tests/test_win_sandbox.py
# Full diagnostic report + test runner (writes redacted per-version report)
python -B run_win_sandbox_check.py
# Real-world 17-scenario field & benchmark suite
python -B run_win_sandbox_field_test.py
```
Or double-click **[RUN_ME.bat](RUN_ME.bat)** (pass `--no-pause` in CI or scripts) to auto-discover all installed Python `3.10–3.15` runtimes on Windows (even off `PATH`) and run both verification suites sequentially. Verified **`PASS=196 FAIL=0 SKIP=0`** + **`PASS=17 FAIL=0 SKIP=0`** on Windows 11 (`Python 3.13.15`, `14.0s` field) and across **7 Windows 10 non-admin Python installs (`3.10.11`, `3.11.9`, `3.12.10` ×2, `3.14.10`, `3.15.2` ×2; `33–35s` check, `17.5–19.3s` field)**. Provided "AS IS" under the [MIT License](LICENSE).
---
## Roadmap
Planned post-`0.1.x` capabilities:
- **Opt-in Interactive / GUI / PowerShell Mode**: Explicit flags to relax `JOB_OBJECT_UILIMIT_ALL` (`0xFF`) or attach a ConPTY (`--pty`) when wrapping interactive console tools, PowerShell scripts, or controlled GUI workflows.
- **Stricter Isolation Profiles**: Support for Less Privileged AppContainer (`--lpac`) profiles to further reduce default `ALL APPLICATION PACKAGES` read visibility on Windows 10/11.
- **Fine-Grained Capability & Network Controls**: Explicit opt-in capability profiles and richer MCP inspection/policy hooks while keeping zero-capability default-deny behavior unchanged.
---
## Documentation Map
| Guide (English) | Arabic | Contents |
| :--- | :--- | :--- |
| [README.md](README.md) | [README.ar.md](README.ar.md) | Overview, quick start, install options, and testing entry points |
| [USAGE.md](USAGE.md) | [USAGE.ar.md](USAGE.ar.md) | Step-by-step usage manual, `wwrap.exe` packaging, API/CLI flags, 5 recipes, troubleshooting |
| [INTEGRATION_HOOKS_WIN.md](INTEGRATION_HOOKS_WIN.md) | [INTEGRATION_HOOKS_WIN.ar.md](INTEGRATION_HOOKS_WIN.ar.md) | MCP client JSON configs & C#/Rust/Go/C++/Node.js integration snippets |
| [WIN_SANDBOX.md](WIN_SANDBOX.md) | [WIN_SANDBOX.ar.md](WIN_SANDBOX.ar.md) | Deep Win32 architecture, hex ACL masks, `py_mirror` internals, full Win10/Win11 benchmarks |
| [SECURITY.md](SECURITY.md) | [SECURITY.ar.md](SECURITY.ar.md) | Supported versions, threat model, boundaries, private vulnerability reporting |
| [CONTRIBUTING.md](CONTRIBUTING.md) | [CONTRIBUTING.ar.md](CONTRIBUTING.ar.md) | Contributor rules, fail-closed checks, PR workflow |
| [CHANGELOG.md](CHANGELOG.md) | [CHANGELOG.ar.md](CHANGELOG.ar.md) | Release history and verified compatibility notes (`0.1.1`) |
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues