Skip to content

Open source CapCut alternative.

TypeScript

docs: document the workspace sandbox and consent boundary

David Le395b6fd9d97b
diff --git a/docs/README.md b/docs/README.md
index 7f7e5c9a..653ee2e9 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -22,6 +22,7 @@ Supported product and engineering guides live in `docs/guides/`. This list is th
- [Context Compaction](guides/context-compaction.md) — how a long conversation is kept whole on disk while each step gets a bounded rolling slice (recent events plus a rolling summary), and how the end-of-run summary is written.
- [Donkey Vision](guides/donkey-vision.md) — the observation layer that turns on-screen windows into structured UI the agent can reason about.
- [Background Input](guides/background-input.md) — driving an app without taking over the cursor or raising it: the foreground/background decision and the delivery lanes.
+- [Workspace Sandbox](guides/workspace-sandbox.md) — the per-task folder as a kernel-enforced jail: what a spawned tool can write, read, and reach, and why a change outside the folder asks first.
**Mac app surfaces**
diff --git a/docs/guides/agent-harness.md b/docs/guides/agent-harness.md
index 472dc6e4..2d05c109 100644
--- a/docs/guides/agent-harness.md
+++ b/docs/guides/agent-harness.md
@@ -223,8 +223,16 @@ Driving a graphical interface is the fallback, used only when the task truly
needs it: a canvas, an Electron app, or a proprietary interface with no
command-line equivalent.
-Shell safety is based on consent, not a blocklist. Each command is sorted by its
-tokens into a risk tier:
+Shell safety has two layers: a kernel sandbox that bounds what a command *can*
+do, and consent that governs what it is *allowed* to do.
+
+Every tool the agent spawns runs inside a macOS sandbox. Its writes are confined
+to the conversation's own folder, so a command that tries to change a file
+elsewhere fails at the kernel even when the model errs. Reads are open — the agent
+can inspect a file the user pointed it at — and the network is reachable for API
+calls and downloads. (See the [Workspace Sandbox](workspace-sandbox.md) guide.)
+
+On top of that, each command is sorted by its tokens into a risk tier:
| Tier | Examples | Behavior |
|---|---|---|
@@ -232,12 +240,14 @@ tokens into a risk tier:
| **reversible write** | changing a setting, opening an app | asks once, then remembers the choice |
| **high risk** | `sudo`, `rm`, `dd`, piping a download into a shell | asks every time, never remembered |
-One exception keeps the agent fluent in the folder it owns: file commands (`mv`, `cp`, `mkdir`, `rm`,
-`chmod`) whose every path is written out in full inside the conversation's own folder run without a
-prompt — including a clean-up chain like `mv … && rm …` where every link is such a command. The agent
-managing the files it created shouldn't have to ask. Anything that can't be read off the command line
-as staying in that folder — a bare name, a glob, a shell variable, or a chained command that is not
-one of those file commands — still asks.
+A file operation (`mv`, `cp`, `mkdir`, `rm`, `chmod`) runs without a prompt only
+when every path it names sits inside the agent's own folder — managing the files
+it created shouldn't require asking. The moment a path reaches a file the user
+owns — a `~` path, an absolute path outside the folder, a clean-up that climbs
+out, a shell variable we can't resolve — the command asks first, and on approval
+the kernel widens to let that one write land. Anything the sandbox does not
+contain — driving other apps, changing system settings, elevated privileges,
+network egress — gates on consent the same way.
The planner discovers what is available by doing. It runs the command it needs
by name, and a "command not found" is just another observation it adapts to —
diff --git a/docs/guides/harness-deep-dive.md b/docs/guides/harness-deep-dive.md
index 618d24dd..099936a7 100644
--- a/docs/guides/harness-deep-dive.md
+++ b/docs/guides/harness-deep-dive.md
@@ -159,12 +159,13 @@ so an attached file reads the turn as action on that file rather than a
misclassified request. Any number of files can ride along; nothing here is
image-specific.
-Because the agent owns that folder, it does not ask permission to read or change
-files there: a reversible file or transform command — a Python mapping script, a
-copy, a `mkdir` — confined to the working directory runs without a consent prompt.
-The dangerous tiers are unchanged: a delete, a privileged command, or anything
-reaching the network still gates every time, and a dangerous neighbor anywhere in
-the command line escalates the whole thing.
+The folder is a kernel-enforced sandbox: every tool the agent spawns is confined to
+write inside it, and the kernel blocks an escape even when the model errs. That
+containment is why a bounded file operation whose paths all stay in the folder needs
+no consent prompt — it changes nothing the user owns. A mutation that reaches outside
+the folder asks first, and approval widens the sandbox for that one command. See the
+[Workspace Sandbox](workspace-sandbox.md) guide for what a confined tool can read,
+write, and reach.
### What stays fixed
@@ -177,10 +178,12 @@ the command line escalates the whole thing.
- **The working directory is seeded; its contents are the model's.** The runtime
creates the folder and resolves relative paths against it; naming, structure,
and grouping inside it are the model's per-step judgments.
-- **Work outside the working directory goes through a protected command.**
- Touching the user's existing files, or deleting, elevating, or reaching the
- network, asks for confirmation and then verifies. Work confined to the agent's
- own folder is exempt; describing a file never changes it.
+- **The sandbox bounds writes; consent governs the rest.** A spawned tool can write
+ only inside the working folder — the kernel enforces it, so a stray or malformed
+ path cannot reach the user's other files. Reads are open. Changing a file the user
+ owns, driving another app, changing a system setting, or reaching the network is
+ outside what the sandbox contains and gates on consent; an approved write then
+ widens the sandbox just for that command.
### Where it lives
diff --git a/docs/guides/workspace-sandbox.md b/docs/guides/workspace-sandbox.md
new file mode 100644
index 00000000..24890a95
--- /dev/null
+++ b/docs/guides/workspace-sandbox.md
@@ -0,0 +1,105 @@
+# Workspace Sandbox
+
+Every task runs inside its own folder. Each tool the agent spawns — a shell
+command, a bundled converter, ffmpeg — runs through a kernel sandbox whose job is
+to bound where it can WRITE: inside the task folder, and nowhere else unless the
+user approved it. Donkey runs whatever commands the model composes, so this
+boundary can't rest on the model behaving: a mistyped path, a path built from a
+web page, or a tool gone wrong is stopped by the operating system.
+
+**The one rule:** a command runs without a consent prompt only when everything it
+changes lives inside the folder Donkey created. The moment a write reaches a file
+the user owns, the user approves it first — and the kernel is there to enforce
+that a command can't quietly escape the folder regardless.
+
+## How it works
+
+```text
+a tool the model runs (shell command, bundled converter, ffmpeg)
+ |
+ v
+launched through the macOS sandbox, scoped to the task folder
+ |
+ v
+write → task folder (+ the user's home, once a prompt approved the command)
+read → open (bundled-tool pipelines: only system libraries + declared inputs)
+network → open
+```
+
+A tool is launched through the macOS sandbox (`sandbox-exec`) under a profile
+built fresh for the task. The runtime builds and applies that profile
+automatically for every task that owns a folder, so confinement holds by
+construction.
+
+The kernel decides what a tool *can* touch; consent decides what it's *allowed*
+to do. They are separate layers: the kernel bounds the filesystem writes, and
+consent (see the harness guide) governs the rest — touching the user's own files,
+driving another app, changing a system setting, reaching out over the network.
+
+## What a tool may touch
+
+| Access | Allowed | Denied |
+|---|---|---|
+| Write | the task folder; the user's home once a consent prompt approved the command | `/System`, `/usr`, other users — and the user's files until a prompt approves the write |
+| Read | open, so the agent can inspect a file the user pointed it at | — (a bundled-tool pipeline stays limited to system libraries + its declared inputs) |
+| Network | open | — |
+
+Reads are open because the agent reading a file is already treated as free — the
+risk it's guarding against is *changing* things, and a read changes nothing. The
+network stays open so a task can call APIs and fetch data; the tools that could
+exfiltrate (a downloader, an interpreter) are gated by consent like any other
+out-of-folder effect.
+
+A bundled-tool pipeline (the caption, shorts, PDF, and media-cut orchestrators) is
+the one exception to open reads: it processes one named input, so its profile
+limits reads to the system and that declared input. A hostile input file then
+can't steer its converter into reading the rest of the disk.
+
+## Two surfaces
+
+The jail is for the **untrusted** surface — the arbitrary tools the model
+assembles and runs. Donkey's own in-process writers, like the file-writing tool
+and the HTML-to-image renderer, run inside the app itself; the kernel sandbox
+confines child processes and the app runs outside it, so those writers keep their
+own destination logic. That split is deliberate: first-party code you author and
+review needs no jail, while a command the model just composed gets one.
+
+## Consent and the folder boundary
+
+A line whose every command is a bounded file operation (`mv`, `cp`, `mkdir`,
+`rm`, `chmod`) runs without a prompt **only when every path it names resolves
+inside the task folder** — the agent managing the files it created shouldn't have
+to ask. A clean-up chain like `mv "<folder>/a" "<folder>/done/a" && rm
+"<folder>/tmp"` qualifies because each link stays in the folder.
+
+The moment an operand leaves the folder — a `~` path, an absolute path elsewhere,
+a `..` that climbs out, or a `$VAR` we can't resolve and so can't trust — the
+command goes through the normal consent prompt, because it would change a file
+the user owns. When the user approves, the kernel widens for that command to let
+the approved write land. Any resolution ambiguity errs toward asking, never away.
+
+Consent also gates what a filesystem boundary can't contain at all: an interpreter
+or a downloader (its effect is the code it runs or the bytes it fetches), driving
+another app, changing a setting, elevated privileges.
+
+The agent does not overwrite an existing user file unless the user explicitly
+asked. By default it writes a new copy or alternate version and leaves the
+original alone.
+
+## Limits
+
+- **The jail bounds writes, not code.** A confined tool can still use the network
+ and read freely; isolating genuinely untrusted *code* is a heavier tier this
+ does not provide.
+- **Scratch space is writable.** The per-user temporary directory and the user
+ cache dirs are writable, because many tools need them to run; they hold no user
+ documents and are cleared by the system.
+- **Approval widens, it doesn't disappear.** An approved command writes within the
+ user's home, so the kernel still blocks `/System`, `/usr`, and other users even
+ for a command the user okayed.
+
+## Where it lives
+
+The runtime's command layer builds the sandbox profile and launches every
+task-work tool through it; the per-task workspace record supplies the folder and
+the declared inputs the profile is built from.