# How dohc isolates workspace apps and bounds their data access

dohc runs personal and shared web apps inside five narrow boundaries instead of giving app code workspace or OS privileges. A closed compiler bundles declared files without running app code, and published frontends run in opaque-origin sandboxed `srcdoc` iframes over a `MessageChannel` broker. Custom SQLite operations run inside per-call QuickJS Wasm instances behind a SQL authorizer, immutable approvals and dual-reach caps gate data access, and workspace secrets stay write-only outside the workspace folder.

This page describes what ships today and where each boundary stops. For full implementation references, see [App compiler containment](https://github.com/dohchq/dohc/blob/main/docs/engineering/app-compiler.md), [Security boundaries](https://github.com/dohchq/dohc/blob/main/docs/engineering/security-boundaries.md), and the [app backend runtime README](https://github.com/dohchq/dohc/blob/main/packages/app-backend-runtime/README.md).

## Five isolation layers at a glance

| Layer | Mechanism | What it blocks | Known boundary limit |
| --- | --- | --- | --- |
| Build (`apps/desktop`, `crates/dohc-compiler-owner`) | Closed esbuild bundle against SHA-256-pinned React 19 and `@dohc/app-kit`; Seatbelt on macOS, Landlock + seccomp on Linux, Job Object on Windows | Arbitrary `package.json` scripts, `node_modules`, build hooks, app-provided plugins, computed imports, compiler network/file egress on macOS and Linux | Windows Job Object enforces memory and process ceilings (owner enforces 60 s wall-clock deadline) with no OS file or network isolation; macOS and Linux memory/process caps sample every 10 ms |
| Browser frontend (`services/share-web`, `apps/mobile`) | Sandboxed `srcdoc` iframe with opaque origin, strict CSP, and typed `MessageChannel` broker (`dohc/app`) | Same-origin access to viewer cookies or credentials, top-level navigation, nested frames, form posts, workers, camera/mic/location | Frontends can still make ordinary browser network requests with data they already received; withdrawal stops future dohc reads and writes, not an open tab's external traffic |
| Collection operations (`packages/app-backend-runtime`) | Fresh `quickjs-emscripten@0.32.0` Wasm instance per call (24 MiB default memory) inside a child process + SQLite authorizer + host-committed journal | Access to filesystem, network, host environment, undeclared SQL tables, transaction control, schema edits, and unsafe SQL functions | No OS filesystem sandbox around the child process itself; confinement rests on Wasm and explicit host callbacks |
| Capabilities and workspace files (`packages/security-contract`, `crates/dohc-engine-files`) | Immutable Owner-approved publications, four-cap Member apps, protected `.env` path floor | Undeclared Collection reads/writes, agent self-approval of Member apps, `.env` leakage to shares, apps, or dohc agent tools | Collection-create form responses are ordinary shared Markdown files; private responses require a dataset with explicitly authorized reads |
| Secrets and outside HTTPS (`packages/service-http`) | Write-only secrets outside the workspace folder + Owner-approved `external` operations in `app.publish.json` + `safeOutboundHttps` | Raw secrets entering bundles, app frames, renderer, CLI, MCP, or echoed responses; SSRF to private/loopback/non-global IPs | Hosted relays still need host or network egress isolation, because IP classification cannot tell whether a public-looking IP routes internally |

## 1. Closed app build and OS containment

When dohc builds a workspace app for local launch or publishing, the desktop captures only the files declared by the app and passes their bytes to one compiler worker per build. The worker parses them with acorn and parse5 and bundles them with esbuild. It refuses `package.json`, `tsconfig`, `node_modules`, and computed imports; esbuild writes nothing to disk, and no app code, build hooks, or app-provided plugins run.

Every allowed import resolves either to a captured app file or to a pre-bundled module in the [built-in app kit](https://dohc.computer/docs/app-kit) (`react`, `react/jsx-runtime`, `react-dom`, `react-dom/client`, `dohc/app`, `dohc/ui`, `dohc/charts`, `dohc/icons`, `dohc/money`, and `dohc/csv`). Staging embeds the SHA-256 of each built-in file into the compiler adapter and worker. When a build runs, both verify every loaded built-in against those embedded hashes before compiling and fold the combined digest into the compiler identity. The prefixes `react`, `react-dom`, `scheduler`, and `dohc` are reserved and cannot be remapped through `packageMap`.

Hostile or malformed source can still make parsing expensive (an unbounded 60 MB single-file input reached 7.2 GB on an Apple M2), and a memory-safety bug in V8 or esbuild could execute code inside the compiler worker. Each platform bounds the compiler owner process differently:

| Bound | Windows x64 (`windowsCompilerOwner.cs`) | macOS Apple silicon, 13.5+ (`crates/dohc-compiler-owner`) | Linux x64, kernel 5.13+ (`crates/dohc-compiler-owner`) |
| --- | --- | --- | --- |
| Wall-clock time | 60 s owner wall-clock deadline | 60 s owner deadline (per-process `RLIMIT_CPU` backstop of 61 CPU s multiplied by available parallelism) | 60 s owner deadline (per-process `RLIMIT_CPU` backstop of 61 CPU s multiplied by available parallelism) |
| Memory | 1 GiB committed memory ceiling on the Job Object (hard failure past limit) | 1 GiB summed physical footprint across tracked tree, sampled every 10 ms | 1 GiB summed anonymous + shared resident memory across tracked tree, sampled every 10 ms (mapped pages only) |
| Processes | 8 active processes ceiling on the Job Object (hard spawn failure past limit) | 8 live processes sampled every 10 ms (plus 1,024 live-process and zombie guard) | 8 live processes sampled every 10 ms (plus 1,024 thread and zombie guard) |
| Teardown | Kill-on-close Job Object handle | Stdin EOF kills tracked tree; supervisor falls back to process group kill | Child subreaper adopts orphans and kills tree; worker dies when owner dies |
| Files and network | No OS file or network isolation; supervisor scrubs environment | Deny-by-default Seatbelt profile: no network, no Mach services, read-only compiler/OS libs, non-executable build folder | Landlock (ABI 1+ required; stronger rights on newer kernels) + seccomp denying `socket`, signals, `io_uring`, `clone3`, x32, mount listing, inotify, tracing, and syscalls newer than Linux 6.17 |

Because macOS and Linux sample memory and process counts every 10 ms, they act as detection thresholds rather than hard ceilings. Measured on an Apple M2, a real compile passed 1 GiB by 24 to 43 MB, a separate allocator touching 14.4 GB/s passed 1 GiB by 33 to 67 MB, and a spawn loop reached 9 to 12 processes against a bound of 8. Both Seatbelt and Landlock leave path metadata readable so Node can start, meaning a compromised worker could check whether a path exists without listing directories or reading file contents.

Each OS sandbox also carries platform-specific escapes that require a V8 or esbuild memory-safety exploit first:

- On macOS, a compromised worker can move a child out of its process group with `setsid` or `setpgid` and exit before the next 10 ms sample; Seatbelt still confines that child, but the owner's memory, process-count, and lifetime bounds no longer reach it (disk use in the build directory is unbounded either way). Seatbelt also does not mediate `kern.procargs2`, so a compromised worker can read other user processes' arguments and environment.
- On Linux, Landlock blocks `/proc` reads, though it cannot prevent executable mappings inside the build directory. Because the 1 GiB memory bound counts mapped pages only, data written to an unmapped memory file or to a build directory on a `tmpfs` `/tmp` (as on Fedora and Arch) is RAM the bound does not see.

See [Desktop capabilities and requirements](https://dohc.computer/docs/desktop-capabilities) for supported architectures and platform requirements.

## 2. Opaque-origin iframes and the `MessageChannel` broker

Published apps run inside a sandboxed `srcdoc` iframe hosted on a per-launch origin, with no same-origin access to viewer cookies or credentials and no top-level navigation. Server CSP headers disallow nested frames, form posts, and web workers inside the app, and the permissions policy denies camera, microphone, and location. On phones, iOS runs the app in an incognito `react-native-webview` process and Android uses dohc's native `app-web-view` refusal rules (on Android, the app shares Chromium's web renderer process with the page editor, so browser rules separate them rather than an OS process boundary).

The frontend reaches workspace data only through the `MessageChannel` client in `dohc/app`, which forwards operation names and typed inputs to the broker. The broker enforces the publication's approved operations and current caller grant on every call. Local desktop static previews run in the Electron session, so the main process attaches a per-launch secret header only to top-level window `dohc-file://` requests and refuses any request without it; preview frames and workers never receive that header.

## 3. Per-call QuickJS Wasm and host-committed SQLite

Transactional Collections back apps with structured SQLite storage and custom JavaScript operations (see [Build an app connected to a Collection](https://dohc.computer/docs/app-backend)). Rather than running authored JavaScript inside the desktop main process or sync relay, dohc evaluates each operation synchronously inside a fresh `quickjs-emscripten@0.32.0` Wasm instance with its own fixed memory (24 MiB default; minimum 16 MiB) inside an isolated child process. The guest receives no filesystem, network, module loader, or host environment. It sees only frozen input, frozen verified `caller` metadata, trusted `nowMs`/`requestId`/`secret`, `db.query`, `db.execute`, `files.attach`, `localDate`, and `refuse`.

SQLite runs behind an explicit authorizer that permits only the Collection's declared tables (plus `json_each` and `json_tree` table-valued functions) and refuses transaction control, schema edits, attached databases, and file or extension functions. Memory limits inside SQLite depend on how the host runtime links SQLite:

- Desktop Electron utility processes and shared-SQLite Node builds (`SQLITE_DEFAULT_MEMSTATUS=1`) enforce `PRAGMA hard_heap_limit=67108864` (64 MiB) directly inside SQLite's allocator, returning `SQLITE_NOMEM` as a clean `resource_limit` refusal without killing the worker.
- Standalone Node.js builds (`services/sync-relay`, compiled with `SQLITE_DEFAULT_MEMSTATUS=0`) ignore `PRAGMA hard_heap_limit`. During budgeted steps, persistent workers run a 50 ms budget watch thread with a 256 MiB peak-RSS kill threshold that terminates and recycles over-budget workers with `worker_budget`; a worker can briefly exceed 256 MiB before the check fires.

The worker never owns commit authority. On a write, the host calls `prepare` inside an open transaction, rechecks caller authority, durably appends the changeset, attachments, and retry receipt to its journal, and only then calls `finalize`. Recovery and replication replay committed SQLite changesets without re-executing authored JavaScript.

## 4. Official publications, Member apps, and protected `.env` files

An app manifest (`app.publish.json`) only requests capabilities. Official Workspace Publications and share-link apps require an immutable Owner approval before they run for viewers; changing source files, dependencies, or declared capabilities changes the candidate digest and requires a new Owner review.

Member apps follow a separate path so teammates can share internal tools without blocking on the workspace Owner. When an Owner or Admin turns on "Members can share apps", a Member or Admin can publish a Personal app without waiting for Owner approval and without touching the synced workspace tree:

- **Four-cap intersection:** Every Collection call a Member app makes runs under the intersection of four caps: the operations the app declares, the author's current Collection grants, the viewer's current Collection grants, and (for anyone other than the author) the exact operation set the viewer approved on first open. Whenever the lower of the author's and viewer's folder levels on that Collection is below Edit, only read-only operations run, even when the workspace Owner or an Admin opens the app.
- **Person-only viewer approval:** Before a Member app runs for anyone other than its author, that viewer approves its operations in a browser or paired phone. Desktop sessions, CLI commands, and MCP tools never allow a Member app, because the relay cannot separate a person from their local coding agent on the desktop sign-in.
- **No outside calls:** Member apps cannot declare workspace secrets or outside HTTPS operations.

Across the workspace, `.env`, `.env.*`, `*.env`, and everything under `.env/` are protected paths (except templates `.env.example`, `.env.template`, and `.env.sample`). The Rust engine encrypts its stored records for protected files under `.dohc/engine/secret.key` and excludes them from shares, app publications, search results, and dohc agent tools. Working `.env` files on disk and retained copies in `.dohc/local` stay plaintext on the owner's computer (on Windows, `.dohc/local` and staged or newly written protected files get user-private DACLs, while existing working `.env` files keep their existing DACLs).

## 5. Write-only workspace secrets and declared outside HTTPS

Workspace secrets used by apps and automations live outside the workspace folder so copying the directory, running file-based agents inside it, or calling dohc CLI and MCP APIs never exposes credentials. Secrets can only be added, replaced, or deleted in Desktop Settings, and saved values never return to the renderer.

- **Local-only workspaces** seal secrets in the desktop profile (`0700`/`0600`) with AES-256-GCM under a random data key wrapped by Electron `safeStorage` (requiring a real OS keyring on Linux; `basic_text` is refused).
- **Synced workspaces** seal secrets on `sync-relay` with AES-256-GCM using HKDF-SHA256 keys and AAD bound to workspace, owner, secret name, usage, allowed hosts, generation, and key ID.

Each `http-header` secret is pinned to 1 to 10 exact lowercase public hostnames. An app sends a host-executed request carrying a workspace secret only through a named operation in `app.publish.json`'s `external` map approved by the workspace Owner in Desktop (refused via CLI, MCP, Personal apps, and Member apps). Typed app inputs fill only whole path segments (rejecting `/`, `.`, and `..`), query values, or body values, never hosts or headers.

Each call first resolves and validates the destination through `safeOutboundHttps`: HTTPS on port 443 only, no URL credentials or IP literals, no `.local`, `.internal`, `.localhost`, or `.home.arpa` hosts, and cancellable DNS A/AAAA resolution (2 s timeout) rejecting private, loopback, link-local, carrier-grade NAT, multicast, and non-global IPs. Right before sending, the app `external` executor verifies caller authorization alongside the secret's `http-header` usage, allowed host, and (on the relay) pinned approval binding, attaches the secret, and sends the request over `safeOutboundHttps` with TLS verification pinned to the resolved IP and canonical hostname and redirects disabled. On its own, `safeOutboundHttps` defaults to a 10 s request timeout (capped at 30 s); the app `external` executor applies a 10 s HTTPS request timeout (separate from the preceding DNS and pre-send checks), caps responses at up to 192 KiB of uncompressed UTF-8 JSON, and refuses any response that echoes the secret in raw, JSON-escaped, URL-encoded, or decoded form.

## What this design does not promise

These limits stay outside the boundaries above:

- **Browser network egress:** Publication approval pins reviewed code and workspace capabilities, not frontend behavior. Ordinary browser requests remain available to the frontend, so a published app can still send data it already received to another server.
- **Windows compiler file and network isolation:** Windows Job Objects cap committed memory and active processes, the owner enforces a 60 s wall-clock deadline, and the supervisor scrubs environment variables, but Windows does not currently enforce Seatbelt/Landlock-equivalent filesystem or network denial on the compiler worker.
- **Compromised compiler escapes on macOS and Linux:** Requiring a V8 or esbuild memory-safety exploit first, a macOS worker can detach a child via `setsid` or `setpgid` before the next 10 ms sample (leaving only Seatbelt on that child, with no memory, process, or lifetime bound; disk use in the build directory is unbounded either way) or read other processes' arguments via `kern.procargs2`, and a Linux worker can allocate unmapped memory-file or `tmpfs` `/tmp` bytes outside the mapped-page RSS bound.
- **Same-OS-user local compromise:** Local keychain vaults keep workspace secrets out of workspace folders and dohc APIs, not away from arbitrary malicious code already executing as the same OS user, and browser-based Member app approval does not defend against software driving the user's signed-in browser.
- **Server operator trust for synced secrets:** Because `sync-relay` holds its sealing key in its environment, the relay operator (self-hoster or dohc Drive) can unseal synced workspace secrets at runtime. Self-hosting keeps that key under your own control.
- **Hosted relay internal routing:** `safeOutboundHttps` blocks non-global IP ranges, but a self-hosted or cloud relay still needs host or network egress rules if internal services sit behind public-looking IP addresses.

To inspect real apps built on these boundaries, browse the [runnable workspace examples](https://dohc.computer/examples) or read [Build an app connected to a Collection](https://dohc.computer/docs/app-backend).
