Skip to content

Quickly sandbox your AI agent.

Python

docs: reflect Windows TCP SMB server and nosharesock in docs

Tyler Payne498b26e500f6
diff --git a/docs/packages/quicksand-core.md b/docs/packages/quicksand-core.md
index 3bed40e..6ff4e7a 100644
--- a/docs/packages/quicksand-core.md
+++ b/docs/packages/quicksand-core.md
@@ -71,7 +71,7 @@ asyncio.run(main())
- **Cross-platform**: Linux, macOS, Windows
- **Platform abstraction**: Automatic detection of accelerators and machine types
- **Save and load**: Save VM disk state to a directory and load it on any machine
-- **File sharing**: CIFS mounts via `quicksand-smb` (pure-Python SMB3 server, invoked as a subprocess via QEMU guestfwd)
+- **File sharing**: CIFS mounts via `quicksand-smb` (pure-Python SMB3 server — a subprocess via QEMU guestfwd on macOS/Linux, an in-process loopback TCP listener on Windows with no admin rights required)
- **Performance optimizations**:
- io_uring disk AIO (~50% lower latency on Linux)
- IOThreads for better concurrent disk I/O (all platforms)
diff --git a/docs/packages/quicksand-smb.md b/docs/packages/quicksand-smb.md
index 59aa9b7..63cc680 100644
--- a/docs/packages/quicksand-smb.md
+++ b/docs/packages/quicksand-smb.md
@@ -2,7 +2,7 @@
Pure-Python SMB3 server for [quicksand](https://github.com/microsoft/quicksand) host-guest directory mounts. Zero dependencies.
-Runs in inetd mode (stdin/stdout). QEMU spawns a new process per guest connection via `guestfwd`. No TCP port is opened on the host.
+Supports two transports. On macOS and Linux it runs in inetd mode (stdin/stdout) — QEMU spawns a new process per guest connection via `guestfwd`, and no TCP port is opened on the host. On Windows, `quicksand-core` serves it in-process via `serve_socket` on a loopback-only TCP listener, so no Administrator rights are required.
## Usage
diff --git a/docs/under-the-hood/04-file-exchange.md b/docs/under-the-hood/04-file-exchange.md
index 7ac5377..2719c37 100644
--- a/docs/under-the-hood/04-file-exchange.md
+++ b/docs/under-the-hood/04-file-exchange.md
@@ -11,21 +11,25 @@ Sandbox(
)
```
-CIFS mounts don't add any QEMU flags for the mount itself. Instead, they work through QEMU's `guestfwd` mechanism, which tunnels a TCP connection from the guest to a host process:
+CIFS mounts don't add any QEMU flags for the mount itself. Instead, on macOS and Linux they work through QEMU's `guestfwd` mechanism, which tunnels a TCP connection from the guest to a host process:
```bash
--netdev user,id=net0,...,guestfwd=tcp:10.0.2.100:445-cmd:/path/to/python -m quicksand_smb --inetd
+-netdev user,id=net0,...,guestfwd=tcp:10.0.2.100:445-cmd:/path/to/python -m quicksand_smb --config /path/to/shares.json
```
`guestfwd` tells QEMU: "when the guest connects to `10.0.2.100:445`, spawn this command and pipe the TCP stream to its stdin/stdout." The command is Quicksand's pure-Python SMB3 server running in inetd mode. It runs one instance per connection with no listening port on the host.
+On Windows, the same SMB3 server runs in-process inside quicksand-core on a loopback-only (127.0.0.1) TCP listener, which avoids requiring Administrator rights. Guest connections reach it through a guestfwd TCP relay in `MOUNTS_ONLY` network mode, or directly via the slirp gateway (`10.0.2.2`) in `FULL` mode.
+
The guest agent then mounts the share:
```bash
mount -t cifs //10.0.2.100/QUICKSAND0 /mnt/code \
- -o username=guest,password=,sec=none,vers=3.0,port=445
+ -o username=guest,password=,sec=none,vers=3.0,nosharesock,port=445
```
+`nosharesock` forces a dedicated TCP connection per mount. Without it, a mount/unmount/mount cycle wedges because the kernel CIFS client tries to resume a session the server already closed.
+
Each mount gets its own SMB share name (`QUICKSAND0`, `QUICKSAND1`, ...). The SMB server maps each share name to the corresponding host directory.
## Hot-mounts
@@ -34,7 +38,7 @@ Each mount gets its own SMB share name (`QUICKSAND0`, `QUICKSAND1`, ...). The SM
handle = await sb.mount("/host/project", "/mnt/project")
```
-Hot-mounts use the same CIFS mechanism. The SMB server is already running (started at boot via guestfwd), so adding a mount just:
+Hot-mounts use the same CIFS mechanism. The SMB server is already available (wired up at boot — via guestfwd on macOS/Linux, or the in-process TCP listener on Windows), so adding a mount just:
1. Registers a new share name in the running SMB server
2. Sends a `mount -t cifs` command to the guest via the agent
diff --git a/docs/under-the-hood/07-network-and-isolation.md b/docs/under-the-hood/07-network-and-isolation.md
index 38aecf0..c9a4986 100644
--- a/docs/under-the-hood/07-network-and-isolation.md
+++ b/docs/under-the-hood/07-network-and-isolation.md
@@ -43,7 +43,7 @@ QEMU's SLIRP networking gives the guest a virtual NAT. The guest sees:
- `10.0.2.2` — the host (NAT gateway)
- `10.0.2.3` — DNS server
-`restrict=on` blocks all outbound connections from the guest to the real network. But it does **not** block `hostfwd` or `guestfwd`. Those are internal QEMU tunnels, not real network connections. This is how file mounts work even in `MOUNTS_ONLY` mode. The guestfwd tunnel to the SMB server is unaffected by `restrict=on`.
+`restrict=on` blocks all outbound connections from the guest to the real network. But it does **not** block `hostfwd` or `guestfwd`. Those are internal QEMU tunnels, not real network connections. This is how file mounts work even in `MOUNTS_ONLY` mode. The guestfwd tunnel to the SMB server is unaffected by `restrict=on` (on Windows the tunnel relays to the in-process loopback TCP listener rather than a stdin/stdout child).
## Port forwarding
diff --git a/docs/under-the-hood/index.md b/docs/under-the-hood/index.md
index 35a0663..6aabe92 100644
--- a/docs/under-the-hood/index.md
+++ b/docs/under-the-hood/index.md
@@ -102,7 +102,7 @@ packages/
**quicksand-qemu** — pre-built QEMU binaries via `get_bin_dir()`. Installed via `quicksand install qemu`. Separate from core so the core works with any QEMU installation.
-**quicksand-smb** — pure-Python SMB3 server for host-guest directory mounting. Runs in inetd mode (stdin/stdout), spawned per-connection by QEMU's `guestfwd=cmd:`. No TCP port opened on the host, no external dependencies.
+**quicksand-smb** — pure-Python SMB3 server for host-guest directory mounting. On macOS/Linux it runs in inetd mode (stdin/stdout), spawned per-connection by QEMU's `guestfwd=cmd:`, with no TCP port opened on the host. On Windows it is served in-process by quicksand-core on a loopback-only TCP listener. No external dependencies.
**quicksand-build-tools** — shared build-time utilities for bundling native binaries into platform-specific wheels. Used by quicksand-qemu build hooks. Provides `BinaryBundler` with platform-specific logic for copying shared libraries, rewriting paths (install_name_tool on macOS, patchelf on Linux), and codesigning.
@@ -189,7 +189,7 @@ quicksand_core/
│ ├── arch.py # Architecture enum + detection
│ ├── os_.py # OS detection, accelerator detection, OS-level config
│ ├── quicksand_guest_agent_client.py # HTTP client for host→guest agent communication
-│ └── smb.py # SMB server hierarchy (QuicksandSMBServer, WindowsSMBServer)
+│ └── smb.py # SMB server hierarchy (QuicksandSMBServer, QuicksandSMBTCPServer, WindowsSMBServer)
├── qemu/ # QEMU-specific subsystems
│ ├── arch.py # QEMU architecture configs (machine types, binary names)
│ ├── platform.py # PlatformConfig, QEMU command building, runtime detection
@@ -304,7 +304,7 @@ HTTP client for host→guest communication over the QEMU user-mode network port
### SMBServer (`host/smb.py`)
-Cross-platform SMB file sharing. `SMBServer` is the abstract base class. `QuicksandSMBServer` (macOS/Linux, pure-Python SMB3 via QEMU guestfwd) and `WindowsSMBServer` (PowerShell) are concrete implementations. Shares are named `QUICKSAND0`, `QUICKSAND1`, etc. Supports dynamic add/remove of shares at runtime for hot-mounting.
+Cross-platform SMB file sharing. `SMBServer` is the abstract base class. `QuicksandSMBServer` (macOS/Linux, pure-Python SMB3 via QEMU guestfwd) and `QuicksandSMBTCPServer` (Windows default — the same pure-Python SMB3 server on a loopback-only TCP listener, no Administrator required) are concrete implementations. `WindowsSMBServer` (PowerShell New-SmbShare) remains available as an opt-in via `QUICKSAND_WINDOWS_NATIVE_SMB=1`. Shares are named `QUICKSAND0`, `QUICKSAND1`, etc. Supports dynamic add/remove of shares at runtime for hot-mounting.
---
@@ -343,10 +343,13 @@ Host Guest (10.0.2.15)
└──────────────────────────┘ └─────────────────────┘
```
+(Diagram shows the macOS/Linux inetd transport. On Windows the same server runs in-process on a loopback TCP listener instead of being spawned per-connection.)
+
**SMB server hierarchy** (`host/smb.py`):
- `SMBServer` — abstract base class with `start()`, `stop()`, `add_share()`, `remove_share()`
- `QuicksandSMBServer` — macOS/Linux: pure-Python SMB3 server (`quicksand-smb`) spawned per-connection by QEMU's `guestfwd` in inetd mode (stdin/stdout). No TCP port opened on the host, no external dependencies.
-- `WindowsSMBServer` — Windows: uses native `New-SmbShare` / `Remove-SmbShare` via PowerShell.
+- `QuicksandSMBTCPServer` — Windows default: the same pure-Python SMB3 server run in-process on a loopback-only (127.0.0.1) TCP listener. Requires no Administrator rights.
+- `WindowsSMBServer` — Windows opt-in (`QUICKSAND_WINDOWS_NATIVE_SMB=1`): uses native `New-SmbShare` / `Remove-SmbShare` via PowerShell.
- `create_smb_server()` — factory that returns the appropriate implementation.
### Boot-time mounts
@@ -382,7 +385,7 @@ Mounts work with `MOUNTS_ONLY` (default) or `FULL` network modes. In `MOUNTS_ONL
sudo mount -t cifs //10.0.2.100/QUICKSAND0 /mnt/data -o username=guest,password=,sec=none,vers=3.0,port=445
```
-In `MOUNTS_ONLY` mode, `10.0.2.100` is the guestfwd virtual IP. QEMU routes guest connections to the SMB server's stdin/stdout. In `FULL` mode, the guest connects to the host via the slirp gateway (`10.0.2.2`).
+In `MOUNTS_ONLY` mode, `10.0.2.100` is the guestfwd virtual IP. On macOS/Linux, QEMU routes guest connections to the SMB server's stdin/stdout. For the Windows TCP server, the guestfwd tunnel is relayed through a small helper (`_tcp_relay.py`) to the loopback listener. In `FULL` mode, the guest connects to the host via the slirp gateway (`10.0.2.2`).
---
@@ -668,7 +671,7 @@ Starts the QMP server on a random free port alongside QEMU. TCP transport is use
| `quicksand_core/host/arch.py` | `Architecture` enum and host CPU detection |
| `quicksand_core/host/os_.py` | OS configs, accelerator detection |
| `quicksand_core/host/quicksand_guest_agent_client.py` | HTTP client for guest agent |
-| `quicksand_core/host/smb.py` | SMB server hierarchy (SMBServer ABC, QuicksandSMBServer, WindowsSMBServer) |
+| `quicksand_core/host/smb.py` | SMB server hierarchy (SMBServer ABC, QuicksandSMBServer, QuicksandSMBTCPServer, WindowsSMBServer) |
| `quicksand_core/qemu/arch.py` | QEMU arch configs (`X86_64Config`, `ARM64Config`) |
| `quicksand_core/qemu/platform.py` | `PlatformConfig`, QEMU command building, runtime detection |
| `quicksand_core/qemu/process.py` | `VMProcessManager` — QEMU subprocess lifecycle |
diff --git a/packages/quicksand-core/README.md b/packages/quicksand-core/README.md
index 3bed40e..6ff4e7a 100644
--- a/packages/quicksand-core/README.md
+++ b/packages/quicksand-core/README.md
@@ -71,7 +71,7 @@ asyncio.run(main())
- **Cross-platform**: Linux, macOS, Windows
- **Platform abstraction**: Automatic detection of accelerators and machine types
- **Save and load**: Save VM disk state to a directory and load it on any machine
-- **File sharing**: CIFS mounts via `quicksand-smb` (pure-Python SMB3 server, invoked as a subprocess via QEMU guestfwd)
+- **File sharing**: CIFS mounts via `quicksand-smb` (pure-Python SMB3 server — a subprocess via QEMU guestfwd on macOS/Linux, an in-process loopback TCP listener on Windows with no admin rights required)
- **Performance optimizations**:
- io_uring disk AIO (~50% lower latency on Linux)
- IOThreads for better concurrent disk I/O (all platforms)
diff --git a/packages/quicksand-core/quicksand_core/sandbox/_lifecycle.py b/packages/quicksand-core/quicksand_core/sandbox/_lifecycle.py
index a7f57b4..1be9ea4 100644
--- a/packages/quicksand-core/quicksand_core/sandbox/_lifecycle.py
+++ b/packages/quicksand-core/quicksand_core/sandbox/_lifecycle.py
@@ -354,7 +354,8 @@ class _LifecycleMixin(_SandboxProtocol):
return (True, "")
# Try virtio-serial first (faster: no guest networking dependency).
- # Fall back to HTTP if the socket path doesn't exist or connection fails.
+ # Fall back to HTTP if the socket endpoint (Unix path or loopback
+ # TCP port) can't be connected.
if self._agent_socket_path is not None or self._agent_socket_port is not None:
try:
from ..host.virtio_serial_agent_client import VirtioSerialAgentClient
diff --git a/packages/quicksand-smb/CLAUDE.md b/packages/quicksand-smb/CLAUDE.md
index bf60013..9a07e4b 100644
--- a/packages/quicksand-smb/CLAUDE.md
+++ b/packages/quicksand-smb/CLAUDE.md
@@ -4,14 +4,14 @@ Pure-Python SMB3 server for quicksand host-guest directory mounting.
## Overview
-An inetd-style SMB3 file server that reads/writes on stdin/stdout. QEMU's `guestfwd=cmd:` spawns one instance per guest TCP connection. No TCP port is opened on the host, eliminating the attack surface that Samba's smbd had.
+An SMB3 file server with two transports. On macOS and Linux it runs inetd-style, reading/writing on stdin/stdout — QEMU's `guestfwd=cmd:` spawns one instance per guest TCP connection, and no TCP port is opened on the host, eliminating the attack surface that Samba's smbd had. On Windows, `quicksand-core` serves it in-process via `serve_socket` on a persistent loopback-only (127.0.0.1) TCP listener, which avoids requiring Administrator rights.
## Acceptance Criteria
- [x] `mount -t cifs //10.0.2.100/SHARE /mnt -o sec=none,vers=3.0` succeeds from Ubuntu guest
- [x] `ls`, `cat`, `stat` work on mounted files (read path)
- [x] `echo "data" > file`, `mkdir`, `rm`, `mv` work (write path)
-- [x] No TCP ports opened on host during operation
+- [x] No TCP ports opened on host during operation (macOS/Linux — Windows uses a loopback-only 127.0.0.1 listener)
- [x] Path traversal attacks blocked (symlink escapes, `../` escapes)
- [x] Dynamic mounts work (add shares after VM boot via config file reload)
- [x] Read-only shares enforce read-only (writes fail with permission denied)
@@ -97,7 +97,7 @@ All SMB3 paths and filenames are UTF-16LE encoded. Length fields are in bytes, n
Timestamps are 100-nanosecond intervals since January 1, 1601. Convert from Unix: `filetime = int((unix_time + 11644473600) * 10_000_000)`.
### Binary stdin/stdout
-QEMU's guestfwd passes raw TCP bytes via stdin/stdout. Must use `os.read()`/`os.write()` on raw file descriptors — NOT `sys.stdin.readline()` or print(). No buffering, no newline translation.
+QEMU's guestfwd passes raw TCP bytes via stdin/stdout. Must use `os.read()`/`os.write()` on raw file descriptors — NOT `sys.stdin.readline()` or print(). No buffering, no newline translation. The socket transport (`serve_socket`) instead uses `recv`/`sendall`, because `os.read()`/`os.write()` fail on socket file descriptors on Windows.
### Credit System
SMB3 uses credits for flow control. Grant generously (256 per response) to avoid stalls.
diff --git a/packages/quicksand-smb/README.md b/packages/quicksand-smb/README.md
index 811dd7f..63cc680 100644
--- a/packages/quicksand-smb/README.md
+++ b/packages/quicksand-smb/README.md
@@ -2,7 +2,7 @@
Pure-Python SMB3 server for [quicksand](https://github.com/microsoft/quicksand) host-guest directory mounts. Zero dependencies.
-Runs in inetd mode (stdin/stdout) — QEMU spawns a new process per guest connection via `guestfwd`. No TCP port is opened on the host.
+Supports two transports. On macOS and Linux it runs in inetd mode (stdin/stdout) — QEMU spawns a new process per guest connection via `guestfwd`, and no TCP port is opened on the host. On Windows, `quicksand-core` serves it in-process via `serve_socket` on a loopback-only TCP listener, so no Administrator rights are required.
## Usage