feat(exec): add a macOS Seatbelt sandbox backend

`tools.exec.sandbox` only supported bubblewrap, which depends on Linux
kernel namespaces, so macOS had no process-level isolation for shell
commands: SECURITY.md told macOS users the sandbox was simply
unavailable.

Add a `seatbelt` backend that generates an SBPL profile for
sandbox-exec(1) with the same policy bwrap applies. The workspace is
read-write, the media directory is read-only, the workspace's parent is
unreadable so config.json and its API keys stay hidden, and everything
else is denied by default.

Two macOS details the profile has to get right, both found by running
the generated command rather than by reading the SBPL reference:

- sh(1) reads `/` while resolving a path, and `(subpath "/usr")` does
  not cover the root itself. Without `(literal "/")` every wrapped
  command aborts during shell startup.
- Denying the parent directory also blocks traversal into the
  workspace, so commands fail with ENOTDIR before they run. The
  ancestors of every allowed path are therefore re-allowed for
  `file-read-metadata` only: they stay searchable, but the config
  directory still cannot be listed or read.

Paths are SBPL-escaped so a quote or backslash in a workspace path
cannot terminate a literal early and widen the rules that follow it.

Network access stays unrestricted to match bwrap, which does not pass
`--unshare-net`. Windows keeps its existing warn-and-run-unsandboxed
path, and selecting `seatbelt` on Linux fails loudly on the missing
sandbox-exec(1) exactly as selecting `bwrap` does on macOS today.

Verified on macOS 26.6.2 against the real sandbox-exec(1): workspace
writes, media reads and /tmp scratch succeed, while writing media,
reading config.json, listing the config directory, writing outside the
workspace and reading ~/.ssh are all denied.

Refs #1448
Refs #2569
This commit is contained in:
LuckTerence authored and Xubin Ren committed 2026-09-10 00:00:44 +08:00
1 parent fea28b1a00
commit e217468e0a
6 files changed
+361 -11

No files matched your search

+15 -5
View File
@@ -69,7 +69,7 @@ chmod 600 ~/.nanobot/config.json
The `exec` tool can execute shell commands. While dangerous command patterns are blocked, you should:
- ✅ **Enable the bwrap sandbox** (`"tools.exec.sandbox": "bwrap"`) for kernel-level isolation (Linux only)
- ✅ **Enable the exec sandbox** (`"tools.exec.sandbox": "bwrap"` on Linux, `"seatbelt"` on macOS) for kernel-level isolation
- ✅ Review all tool usage in agent logs
- ✅ Understand what commands the agent is running
- ✅ Use a dedicated user account with limited privileges
@@ -77,16 +77,26 @@ The `exec` tool can execute shell commands. While dangerous command patterns are
- ❌ Don't disable security checks
- ❌ Don't run on systems with sensitive data without careful review
**Exec sandbox (bwrap):**
**Exec sandbox (bwrap on Linux, seatbelt on macOS):**
On Linux, set `"tools.exec.sandbox": "bwrap"` to wrap every shell command in a [bubblewrap](https://github.com/containers/bubblewrap) sandbox. This uses Linux kernel namespaces to restrict what the process can see:
Set `"tools.exec.sandbox"` to wrap every shell command in an OS sandbox. Both backends enforce the same policy:
- Workspace directory → **read-write** (agent works normally)
- Media directory → **read-only** (can read uploaded attachments)
- System directories (`/usr`, `/bin`, `/lib`) → **read-only** (commands still work)
- Config files and API keys (`~/.nanobot/config.json`) → **hidden** (masked by tmpfs)
- Config files and API keys (`~/.nanobot/config.json`) → **hidden**
- Everything else, including `~/.ssh` → **denied**
Requires `bwrap` installed (`apt install bubblewrap`). Pre-installed in the official Docker image. **Not available on macOS or Windows** — bubblewrap depends on Linux kernel namespaces.
| Backend | Value | Platform | Requires |
|---------|-------|----------|----------|
| [bubblewrap](https://github.com/containers/bubblewrap) | `"bwrap"` | Linux | `bwrap` (`apt install bubblewrap`). Pre-installed in the official Docker image. |
| Seatbelt | `"seatbelt"` | macOS | `sandbox-exec(1)`, shipped with macOS. |
**Windows has no backend**: nanobot logs a warning and runs the command unsandboxed.
The backends hide the config directory differently. `bwrap` masks the workspace's parent with a tmpfs, so it disappears from directory listings. Seatbelt has no mount namespace, so it denies the parent instead — the directory still appears in listings, but its contents are unreadable.
Neither backend restricts network access.
Enabling the sandbox also automatically activates `restrictToWorkspace` for file tools.