# Zero-Dependency Multi-Profile AI Browser Isolation in 1.18 MiB of Rust: Per-Context Proxy Guards, 42 MiB Moli Pools, and 2-Phase Human Handoff

> Source: <https://dev.to/wasabi_hu_d2b4b4d9b9f6bda/zero-dependency-multi-profile-ai-browser-isolation-in-118-mib-of-rust-per-context-proxy-guards-3ooh>
> Published: 2026-12-06 05:42:00+00:00

**Key takeaway:** sessfork v0.4.1 adds named profile vaults, per-context proxy leak guards with preflight TCP checks, and a loopback CDP orchestrator in a 1.18 MiB zero-dependency Rust binary, after probes showed invalid proxy schemes pass createBrowserContext and only fail at navigation.

Single-state headless browser setups work fine until your agents need **multiple isolated accounts, per-profile proxy routing, external Python/CLI CDP orchestration, or a clean escape hatch when headless runs hit interactive SSO / 2FA walls**.

Once you cross that line in production, four systems problems show up immediately:

`storageState` file—or if an MCP tool accepts arbitrary `proxyServer` URLs straight from LLM parameters—a single prompt-injected webpage can trick an agent into routing authenticated requests through an attacker-controlled proxy.`FD_SETSIZE=1024` ceiling:`moli` process beyond `BrowserContext` s`1,024` (`1,063` observed via `lsof`), triggering `net::ERR_CONNECTION_REFUSED` on subsequent navigations.`/json/list` on a shared port lets external worker A inspect and attach to worker B's targets.
In `sessfork`[` v0.4.1`](https://github.com/wasabihu/sessfork/releases/tag/v0.4.1), we solved all four inside our **`1,233,344`-byte (`~1.18 MiB`)** pure-` std` Rust binary with **zero new Rust crates** and **zero Python runtime dependencies**: named Profile Vaults with per-context proxy leak guards (`P0-1`), a loopback process-isolated CDP orchestrator (` serve-api`, `P0-2`), and a 2-phase non-blocking human takeover tool (` browser_handoff`, `P0-3`).

`moli 1.1.29` & Chromium)
Before writing isolation layers, we ran paired positive/negative CDP probes against `moli`` 1.1.29` (over anonymous pipe FDs 3/4 `--remote-debugging-pipe`) and local Chromium (`--cdp-url`):

| CDP Probe | Observed Behavior ( `moli 1.1.29` / Chromium) | Design Takeaway | 
|---|---|---|
| `createBrowserContext` (`proxyServer` ,`bypass` ) | Returns isolated `browserContextId` ; parallel contexts hit only their own proxy (`PROXY_HIT` ) | Per-context proxy isolation works natively inside one engine process | 
| Dead proxy ( `http` /`socks5` closed port) | Immediately fails with `ERR_CONNECTION_REFUSED` (**no silent direct fallback** ) | Paired with preflight TCP checks, prevents accidental IP leakage | 
| Invalid scheme ( `ftp://127.0.0.1:8080` ) | `createBrowserContext` succeeds; navigation later fails (`ERR_FAILED` ) | Rust must validate schemes upfront via `ProxySpec` before context spawn | 
| `Emulation.*Override` (TZ / Locale / UA / Geo) | All return `{}` ;`timeZone` &`navigator.language` update to`America/New_York` /`en-US` | Apply deterministic timezone/locale/geo overrides on every attached tab | 

Implemented across [`profile.rs`](https://github.com/wasabihu/sessfork/blob/main/rust/sessfork-mcp/src/profile.rs), [`proxy.rs`](https://github.com/wasabihu/sessfork/blob/main/rust/sessfork-mcp/src/proxy.rs), and [`profiles.py`](https://github.com/wasabihu/sessfork/blob/main/src/sessfork/profiles.py), named vaults preserve 100% compatibility with `~/.sessfork/state.json` while adding strict boundaries:

`~/.sessfork/profiles/<name>/`):`^[a-z0-9][a-z0-9_-]{0,47}$` (blocking `default`, `..`, and hidden names). Both Rust and Python check for symlinks `O_NOFOLLOW` + `0600` atomic rename.`browser_tabs` rejects `proxy`, and `proxyBypassList` parameters outright. Only local `profile` names are accepted, and named contexts hydrate `state.json`—never leaking `ps aux`:` http://user:pass@host:port`) are parsed into `ProxySpec`, stripped of `userinfo@` in every CLI argument, log line, and error receipt, and answered in memory via CDP `Fetch.enable({ handleAuthRequests: true })` / `Fetch.authRequired`.`--ephemeral`:` requireProxy: true` (default), a `3s` loopback-safe TCP probe verifies proxy reachability before any context spawns. Optional outlet verification (`preflightUrl` / `expectedCountry`) executes only when explicitly configured (zero background telemetry by default). 

```
# Create an ephemeral US vault with proxy + timezone/locale alignment
sessfork profile create us-qa \
  --domains example.com \
  --proxy socks5h://127.0.0.1:1080 \
  --timezone America/New_York \
  --locale en-US \
  --ephemeral

# Or fork specific domains from your active Chrome profile into a named vault
# (uses --vault so existing -p / --profile stays orthogonal for Chrome source directories)
sessfork github.com --vault work -p "Profile 4"
```

`serve-api` — A `3.1 MiB` Pure-`std` Orchestrator for `42.2 MiB` Isolated CDP Sessions
To bypass single-process FD limits and prevent one external worker from inspecting another worker's CDP targets on a shared port, `sessfork-mcp serve-api` ([`api_server.rs`](https://github.com/wasabihu/sessfork/blob/main/rust/sessfork-mcp/src/api_server.rs)) acts as a lightweight OS-process orchestrator:

`127.0.0.1`, generates a `/dev/urandom` on Unix, `SystemFunction036` on Windows) compared in constant time, enforces strict `Host` / `Origin` / `Sec-Fetch-Site` anti-DNS-rebinding checks, and caps headers (`16 KiB`) and bodies (` 64 KiB`).` 409 Conflict` with the owning `activeSessionId`. Routes like `/cookies` or `/state` are deliberately omitted. Every child `chrome-headless-shell` process is reaped via Unix `killpg` or Win32 Job Objects when stopped or on `SIGTERM`.` cdpWsUrl` bound only to that profile's child process, zero-dependency Python `api_client.py`` sess.cdp_ws_url` straight into Playwright, `browser-use` (`Browser(cdp_url=sess.cdp_ws_url)`), or `agent-browser --cdp ...` without requiring custom WebSocket auth headers.

``` python
from sessfork.api_client import open_profile_session

# Start daemon once: sessfork-mcp serve-api --port 7331
with open_profile_session(
    "work",
    base_url="http://127.0.0.1:7331",
    engine="moli",  # or "chrome" when full WebGL/Blink fidelity is needed
) as sess:
    # Hand sess.cdp_ws_url directly to Playwright connect_over_cdp
    # or browser-use Browser(cdp_url=sess.cdp_ws_url)
    print("Isolated CDP endpoint:", sess.cdp_ws_url, sess.timezone, sess.locale)
# Context exit automatically calls /stop and reaps the child process (0 orphans)
```

Measured on **macOS 26.6.2 (Apple Silicon `arm64`)** running `sessfork-mcp 0.4.1` and **8 simultaneous process-isolated `moli 1.1.29` sessions** with distinct timezones/locales and seeded cookies (reproducible harness documented in [`docs/benchmarks.md`](https://github.com/wasabihu/sessfork/blob/main/docs/benchmarks.md)):

| Metric ( `serve-api --max-sessions 16` , 8 Isolated`moli 1.1.29` Processes) | Measured Result | 
|---|---|
| **Cold `serve-api` ready latency** | **`8.7 ms`** (includes` 0600` 256-bit token generation & JSON ready signal) | 
| **Per-session start latency (p50 / mean / max)** | **`43.8 ms` / `76.0 ms` / `222.1 ms`** (process spawn + cookie hydration +` Emulation.*` overrides) | 
| **`serve-api` daemon RSS** | **`3.1 MiB`** | 
| **Total stack RSS (daemon + 8 isolated `moli` processes)** | **`340.9 MiB`** (**` 42.2 MiB` / session avg** ) | 
| **Cross-session CDP & timezone verification** | **`8 / 8 PASS`** (` 0` cross-profile leaks) | 
| **Orphan processes after `SIGTERM`** | **` 0`** | 

`browser_handoff`)
Even when `--compact --diff` slashes cumulative LLM input tokens by **`-85.4%`**, automated flows still hit interactive MFA, passkeys, or human verification walls. Rather than touching CAPTCHA-bypass tooling, `sessfork` adds MCP tool #20 [`browser_handoff`](https://github.com/wasabihu/sessfork/blob/main/rust/sessfork-mcp/src/handoff.rs) (`start` / `status` / `complete` / `cancel`):

`start`:` window.localStorage` (preserving in-flight OAuth PKCE `code_verifier` / CSRF state), writes them into an isolated `0700` `--user-data-dir`, and pops a desktop Chromium window (` 1,374.0 ms` measured on real macOS Chrome `--new-window`) without touching your daily Chrome profile.` MAX_ACTIVE_HANDOFFS=1`, `2s` start cooldown, and bounded timeouts (`60..=3600s`, default `600s`).` complete`:` localStorage` back into the headless context, `{start_host, end_host} ∪ allowDomains`` 0` raw secrets in MCP replies).`v0.4.1`
Adversarial diff review, `scripts/security_verify.py` (`D1..D13`), and the 3-OS release matrix caught four subtle defects before shipping ([`20fbb38`](https://github.com/wasabihu/sessfork/commit/20fbb38), [` 06de95f`](https://github.com/wasabihu/sessfork/commit/06de95f)):

`profile.json` load validation:`create` paths rejected malformed domains and unsupported `encryption` values, whereas load paths in `profile.rs` and `profiles.py` trusted existing disk fields. Both now enforce `schemaVersion == 1`, `encryption == "none"`, valid `engine`, and public-suffix domain rejection on load.` Drop` after explicit cleanup:`terminated: bool` guard to `ActiveHandoff` and `ManagedApiSession` so explicit `cleanup()`/` wait()` prevents `libc::killpg`.` handoff start`:` pkce_carried=True` asserted in `D13.2`).`-D warnings` errors:`_clean_profile_ref` / `_clean_session_id` slug guards in `SessforkApiClient`, and scoped Unix `api_server.rs` cleanly under `#[cfg(unix)]` alongside a `1,233,344` bytes (`~1.18 MiB`) stripped Rust binary; `73 / 73` Rust unit tests (`cargo test --locked --all-targets`), `clippy -- -D warnings` issues across macOS/Linux/Windows, `66 / 66` Python `unittest` cases, and `29 / 29 PASS`` D1..D13` in `docs/security-report.md``--engine dual` or `engine="chrome"` in 

```
# Install sessfork + native Rust sessfork-mcp (v0.4.1)
curl --proto '=https' --tlsv1.2 -fsSL \
  https://raw.githubusercontent.com/wasabihu/sessfork/v0.4.1/install.sh \
  | bash -s -- --with-rust-mcp

# Or install the standalone Rust binary via Homebrew
brew install wasabihu/tap/sessfork-mcp
```


