Daemon

Security

The daemon's trust model in v0.1, what is enforced, including the child sandbox, and what is not.

The daemon trusts its OS user. It does not trust its children, the network, or a relay. The normative statement is wire protocol section 7; this page says what v0.1 enforces.

Experimental: child isolation. Child isolation (the macOS and Linux sandbox) is experimental and best-effort in 0.1.0. It is not a security boundary. Run agents you do not trust as a separate OS user. The hard boundary is the daemon's approvals, pairing and the encrypted channel: no tool call runs without an approval from a paired controller.

Enforced

  • Keys, not accounts. Every viewer connection is a Noise IK handshake that proves a paired key; the daemon proves its own key in every handshake and at relay registration. Unknown and revoked keys are rejected.
  • Pairing. Offers are single use and expire. The secret never leaves the link's URL fragment. A replayed handshake message changes nothing; only a live viewer's first decrypted message commits the pairing. Confirmation compares full 26-character fingerprints. See Pairing.
  • End to end through a relay. The relay sees hub ids, connection counts, sizes and timing. It never sees requests, events or approvals, and cannot pair itself or impersonate the daemon. The daemon's relay token is a bearer token in the WebSocket upgrade, so a plain ws:// relay that is not on loopback is refused (daemon.invalid_request): the token would cross the network in cleartext. Use wss://, or opt in for a trusted network with --relay-allow-insecure-ws (connectRelay({ allowInsecureWs: true })).
  • Forward secrecy. Ephemeral keys per channel; channel keys live only in memory.
  • Local socket. A Unix domain socket inside the daemon home (0700), socket file 0600, bearer token from <home>/token (0600). Any request with an Origin header is refused, so a web page cannot reach it.
  • Direct endpoint and web pages. Any web page can try to open a WebSocket to 127.0.0.1:7070. The daemon answers 403 to an upgrade whose Origin is not allowed, before it takes one of the 8 handshake slots per address, so idle sockets from a page cannot crowd out local viewers. Allowed: the Console's origin (from --console, default http://127.0.0.1:7071, with localhost and 127.0.0.1 interchangeable) and each --allow-origin. No Origin header means a client that is not a browser, which is allowed; two slots are kept for those on loopback. A page still cannot pair or connect without a paired key; this protects availability only. See Pairing.
  • Failed saves. A revoke removes the key from memory at once and closes its channels, even when writing peers.json fails; the request then fails and a retry writes again. A pairing whose save fails stores no peer. A Console home is denied at once and a retry of a failed save writes again.
  • Roles. viewer, controller and owner (the local token) are fixed per connection; a request outside the role fails with daemon.forbidden.
  • Approvals. Fail closed on timeout and on session end. The local token cannot answer approvals unless localApprovals: true. Every allow must carry the action_digest of the whole action, and it must match, or it is refused. See Approvals.
  • Child environment. See Child environment below: the CLI passes agents a minimal environment, the library inherits everything by default. Either way every VIEWPORT_* variable and every variable holding a daemon secret is dropped, and LD_* and DYLD_* in session.start.env are refused.
  • Store. Records and logs are written atomically with 0600. One writer per home; the lock is never stolen.

Child environment

The viewport-daemon CLI (serve and up) passes agents a minimal environment. A child gets only these variables from the daemon's environment, when they are set: PATH, HOME, USER, LOGNAME, SHELL, TMPDIR, TEMP, TMP, LANG, LANGUAGE, LC_ALL and every other LC_*, TZ, TERM, COLORTERM, SSH_AUTH_SOCK, DISPLAY, XDG_RUNTIME_DIR, NODE_EXTRA_CA_CERTS, SSL_CERT_FILE, SSL_CERT_DIR (and SystemRoot, ComSpec, PATHEXT on Windows). This is MINIMAL_ENV_KEYS. Credentials you exported in the shell that started the daemon, such as AWS_*, GITHUB_TOKEN, NPM_TOKEN or a database URL, do not reach agents.

Two ways to give an agent more:

  • --env-allow NAME on serve or up (repeatable, exact names) passes that variable from the daemon's environment to every session, for example --env-allow GITHUB_TOKEN or --env-allow HTTPS_PROXY.
  • A session's own env (session.start.env, viewport-daemon run --env NAME=value, env in supervisor.start()) sets variables for that session only. Prefer it for credentials one task needs.

claude-code sessions also get the variables Claude Code authenticates with, from the daemon's environment: ANTHROPIC_API_KEY, CLAUDE_CODE_OAUTH_TOKEN, ANTHROPIC_AUTH_TOKEN, CLAUDE_CODE_USE_BEDROCK, CLAUDE_CODE_USE_VERTEX, CLAUDE_CODE_USE_FOUNDRY and ANTHROPIC_BASE_URL. Other runners never see them. The token stored with viewport-daemon claude-token is injected as before. Bedrock and Vertex need their cloud credentials too: pass them with --env-allow (for example AWS_PROFILE, AWS_REGION), knowing every session sees them.

The library (createSupervisor()) inherits the daemon's whole environment by default (env: { inherit: "all" }), so an embedding program decides what its children see. Pass env: { inherit: "minimal", allow: ["NAME"] } for the CLI's behaviour. drop removes more names or patterns, and set adds fixed values.

Under every policy, every VIEWPORT_* variable is dropped, and so is any variable whose value contains a known secret, whatever its name and wherever the secret sits in the value (Authorization=Bearer <token>, a URL with ?t=<token>, a JSON blob): serve() registers the local token and the relay token, connectRelay() registers its daemon and viewer tokens, and supervisor.addSecret() adds your own.

Child isolation

By default (child_isolation: "home") every process a runner starts runs in an OS sandbox: the command runner over pipes and in a terminal, and every Claude Code process the Agent SDK starts (through the SDK's spawnClaudeCodeProcess hook). Custom runners get the same sandbox as io.sandbox and must spawn what io.sandbox.wrap() returns. hello reports child_isolation: "home".

The sandbox reduces risk; it is experimental and best-effort in 0.1.0, and not a security boundary for agents you do not trust. It keeps a misbehaving or prompt-injected agent away from the daemon's keys, your persistence locations and the local servers that would run code for it, and each escape found in review has a regression test, which does not mean none remain. But it runs as your OS user, on a deprecated macOS facility and on Linux user namespaces, and it leaves the network open. The real boundary is a separate OS user for the daemon (or a VM or container). Use one for untrusted agents.

What the sandbox enforces

Children can neither read nor write:

  • the daemon home, by real path: the configured home, $VIEWPORT_HOME and ~/.viewport/daemon, including the token, the identity, offers, peers and the local socket (connecting to it is refused too);
  • every other daemon's home, from the registry of daemon homes (see below), and the registry itself;
  • Console's home ($VIEWPORT_CONSOLE_HOME, ~/.viewport/console, and any home a Console names when it pairs over the local socket; see below) and ~/.viewport/viewer;
  • the browser profile roots for Chrome (stable, beta, canary or unstable), Chromium, Edge, Brave and Firefox, plus Safari on macOS, under $HOME and the account's home. Linux also covers $XDG_CONFIG_HOME, snap and flatpak locations. The list is BROWSER_PROFILE_ROOTS in src/sandbox/paths.ts;
  • anything you add with sandbox.denyRead.

Each daemon denies its own home, but an agent under daemon A could otherwise read daemon B's custom home (--home ~/vpd-try): its token, identity and peers. So every daemon records the real path of its home in the registry of daemon homes before it serves anything, one 0600 file per home in ~/.viewport/daemon-homes/ (0700), and every daemon denies every listed home that exists now, as a directory you own. An entry whose home is gone denies nothing and refuses nothing; if the directory comes back, the daemon that uses it registers it again when it starts. The daemon re-reads the registry at each session start, so a home registered (or recreated) later is denied to every session started after it; sessions already running when another daemon registers keep the policy they started with. A session cwd may contain another daemon's home (a project with a test daemon's home inside, /tmp, ~/projects): the home stays unreadable and unwritable, and the cwd and every directory between it and the home cannot be renamed or removed, so the home cannot be moved out from under its rule (macOS denies writes to those paths themselves; on Linux the home is a mount point, and the directories between are bound onto themselves). A cwd inside another daemon's home is refused, and the daemon's own home and the fixed roots above keep the strict rule: a cwd that contains them is refused. Entries are never removed automatically; delete a home's file there to drop it. A registry the daemon cannot trust (a symlink, another owner, access for group or others, an entry that is not { "v": 1, "home" } or does not match its file name) fails closed: the daemon does not start, and no session starts until it is fixed. hello.isolation lists the registered homes. $VIEWPORT_DAEMON_HOMES_DIR in the daemon's own environment moves the registry (the test suite and example runner use it). For a throwaway daemon, put its home under ~/.viewport/ (--home ~/.viewport/vpd-try): children can never use a directory there as their cwd or write to it, and the registry hides it from every other daemon's sessions.

A Console started with its own home (--home ~/vpc-try) while the daemon's environment has no $VIEWPORT_CONSOLE_HOME would sit outside these roots, and an agent could read its CLI token. So the Console sends its home as console_home in its local pair.offer. The daemon resolves it by real path, requires an existing directory (never /, a home directory or an ancestor of one), denies it to every child spawned from then on, and keeps it in <home>/console-homes.json (0600), so it stays denied after a restart. That file fails closed: if it exists but is damaged, a symlink, owned by another user or open to other users, the daemon refuses to start and names the file. This only ever adds a deny root, and only the local socket can do it: a direct or relay peer that sends console_home is refused. Children already running when the Console pairs keep the policy they started with; pair the Console before starting agents, or restart them. hello.isolation lists the real paths of the deny roots that hold viewer and Console secrets, so a Console can check its own home is there. Library users call server.addConsoleHome(dir).

Children can write only to the session's cwd, the spawn's own temp dir, the runner's state and anything you add with sandbox.allowWrite. State paths come from the daemon's own environment, never from session.start.env.

Each spawn gets a private temp dir, vpd-sess-<daemon pid>-XXXXXX (0700) in the daemon's temp dir, and TMPDIR, TMP and TEMP point at it. On macOS it is the only writable temp location; on Linux it is bound at /tmp and TMPDIR is /tmp. The shared temp dirs ($TMPDIR, /tmp, /private/tmp, macOS's per-user temp dir) are not writable: tools keep executable caches there (tsx's $TMPDIR/tsx-<uid>, compilers, package managers), and a sandboxed agent that could plant code in one would run it as you on your next unsandboxed run. The daemon removes the dir, by its exact path, when the spawn ends; a daemon that was killed leaves it behind, and the next daemon removes it once its pid is gone and it has not changed for an hour. Removal never follows a symlink: the dir is first renamed into the daemon's trash ($TMPDIR/vpd-trash-<uid>, 0700, denied to every child, in a temp dir no child can write), so a process that survived its session can no longer touch it, and only then deleted with rm -rf (a physical walk that checks each directory as it descends). A child that swaps a subdirectory for a link to your files mid-delete cannot make the daemon delete them. On Linux the PID namespace is gone before any removal. A tool that writes to a hard-coded /tmp/... path fails on macOS; on Linux it writes the private /tmp. On Linux nothing of the host's /tmp is visible except allowlisted sockets there (ssh-agent's /tmp/ssh-*/agent.N), which are bound into the private /tmp.

Devices: children may write /dev/null, /dev/zero, /dev/random, /dev/urandom, /dev/dtracehelper and their own descriptors (/dev/fd/N, /dev/stdout). No terminal device is reachable except the session's own pty: every other /dev/ttys*, /dev/tty* and /dev/pty* is another terminal of yours (a Terminal tab, an ssh session, tmux), and a child that could open one could read its keystrokes or write escape sequences and fake prompts into it. On macOS the profile denies them for reads and writes; a terminal session gets its own slave (by path, so tty and tools that open ttyname(0) work) and /dev/tty back. Pipe sessions and the Claude Code spawn have no controlling terminal and get no terminal device, /dev/tty included. On Linux bwrap mounts a fresh /dev with its own devpts instance, so no host terminal exists inside; a terminal session reaches its pty through its inherited descriptors and /dev/tty. Programs that create a new pseudo-terminal inside the sandbox (tmux, script, expect) do not work on macOS.

Some places that run code later, outside the sandbox, are write-protected whatever the cwd or allowWrite says: shell startup files (.zshrc, .zshenv, .zprofile, .bashrc, .bash_profile, .profile, ~/.config/fish), ~/.gitconfig and ~/.config/git, ~/.ssh, ~/Library/LaunchAgents and login items on macOS, ~/.config/systemd, ~/.local/share/systemd, ~/.config/autostart and environment.d on Linux, ~/.claude, ~/.claude.json and a custom $CLAUDE_CONFIG_DIR, ~/.local/bin and ~/bin, every directory on the daemon's PATH (except a project's own node_modules/.bin) with its prefix, toolchain shims, versions and env files (TOOLCHAIN_PATHS), the daemon's own package wherever it lives (a source checkout too) with every runtime dependency it loads or execs and the Node.js install that runs it (PERSISTENCE_PATHS, TOOLCHAIN_PATHS, PACKAGE_CODE_PATHS and dependencyClosure in src/sandbox/paths.ts). That list cannot be complete: editors, language toolchains and package managers load code from many more places in your home. So the real rule is the write allowlist above, plus where a cwd may be. On Linux, bwrap also sets no_new_privs, so setuid helpers such as crontab cannot run.

A session cwd must be an ordinary project location. It is refused with daemon.invalid_request when it is /, your home directory (in either spelling, if $HOME is a symlink), inside any dot-directory of your home (~/.config, ~/.vscode, ~/.cargo and so on), inside ~/Library or ~/Applications, inside a toolchain or package-manager root (CACHE_ROOTS in src/sandbox/allowlist.ts, such as ~/go, plus CARGO_HOME, GOPATH, GOMODCACHE and similar from the daemon's environment), inside a system location (/usr, /opt, /Library, /var, /Users/Shared and others, temp excepted), inside a denied or protected root, or a parent of one. To run agents somewhere refused on purpose, list it in sandbox.allowCwd (--sandbox-allow-cwd). Deny and protected roots stay refused even then. Runner state paths pass the same protected-root checks, so a state dir that resolves to your home is refused.

The daemon's own package is the directory holding its package.json: the clone when you run from source, the package directory (node_modules/@viewportai/daemon) when installed. Its dist, node_modules and package.json run as you, outside the sandbox, the next time you run a daemon command, restart it or import it, so no child ever writes them. An installed copy (any directory under a node_modules) is read-only whole, its not-yet-existing node_modules included: a package created there would shadow its hoisted dependencies. A session cwd that is the package or is inside it is refused with a message that says so. A cwd that contains it is fine: a project that installed the package, or a directory holding the clone, is an ordinary cwd. To let agents work on the daemon's own source, list the clone in sandbox.allowCwd: the cwd is then allowed, and dist, node_modules and package.json stay read-only, so build outside the session. A cwd inside dist or node_modules is refused even then, and an installed copy is never a cwd. For a session elsewhere the whole package is read-only.

The daemon's dependencies. npm install @viewportai/daemon in a project hoists its dependencies (ws, zod, node-pty, the Claude Agent SDK and theirs) into the project's own node_modules, inside the session cwd. The daemon loads them as you, outside the sandbox: ws and zod at the next start, node-pty and the SDK at the first session that needs them, and node-pty's spawn-helper is exec'd outside the sandbox at every terminal spawn. So when the sandbox is created the daemon computes its runtime dependency closure the way Node resolves it: from its package root, every package in dependencies, optionalDependencies and peerDependencies (not devDependencies, and not the vitest peer, which only your own test process loads), transitively, each found by walking the node_modules directories above the dependent's real root. Every spawn write-protects:

  • the real root of every package in the closure, and node-pty's spawn-helper by name;
  • each pnpm virtual-store directory that holds one (node_modules/.pnpm/<id>/node_modules, whose entries are the symlinks pnpm resolves through), and any other symlink entry that leads to one (npm link);
  • every place Node looks before the place a package was found (a scope directory's node_modules, such as node_modules/@viewportai/node_modules/ws), and every place it would look for a dependency that is not installed, such as the optional Claude SDK peer or ws's optional bufferutil: a package planted there would load instead.

On macOS each is a file-write* deny, existing or not, and renaming any directory above one is denied. On Linux each existing one is a read-only bind over the writable ones, verified by the relay like the others. A path that does not exist yet gets an empty placeholder directory, bound read-only: the topmost missing directory above it (an empty node_modules or scope directory changes no resolution), or an empty directory with the package's name when the package is not installed anywhere (Node treats it as not installed, as before). Placeholders stay after the spawn, since removing one could unmount it under another running spawn. A session cwd inside any of these paths is refused.

The set is computed once, at sandbox creation, and checked before every spawn: if a dependency now resolves somewhere else, or a package appeared where Node would look first (you installed the SDK in the project while the daemon ran), the spawn is refused with daemon.runner_unavailable until the daemon restarts and protects the new layout.

The tradeoff, decided: only these listed paths are protected, never a project's node_modules as a whole. An agent's npm install in the project can still add, change and remove every other package, which is what agents need to work on the project. It cannot change the daemon's own dependencies, and it fails if it would (an upgrade of ws, a newly installed Claude SDK or bufferutil while the daemon runs from that project). Removing or renaming the project's node_modules itself is denied too. The binaries in node_modules/.bin and the project's own code and scripts are project files like any other (see "Your projects" below): a command you run from the project later runs what the agent left there.

allowWrite is a tradeoff the owner makes, not a safe setting. It is daemon config only: no request, viewer or session can set it. Each entry logs a warning at startup: code written here may run outside the sandbox later. Caches are code. Crate sources are compiled with their build.rs, Go modules and npm packages are imported by your builds, and Python site-packages run .pth files at every interpreter start. Anything an agent can write in a cache can run later, outside the sandbox, when you build. An entry at or above a toolchain root (~/.cargo, ~/.local, ~/go, ~/.gradle, ~/Library/Python and the rest of CACHE_ROOTS) is refused outright. An entry below one (~/.cargo/registry, say) is accepted with that warning, so share a cache only with agents you would let run code in your builds.

Every parent of a denied or protected root is write-protected too, up to /, so a child cannot rename, unlink or replace a directory to move a root out from under its rule. macOS denies writes to each parent's exact path. On Linux, each parent inside a writable tree is bound onto itself, and a mount point cannot be renamed or removed. A root reached through a symlink (a symlinked daemon home) also has the link itself protected. A read-only entry protects both a symlink's own path and its target.

What each platform blocks

macOS runs every child under a generated sandbox-exec profile. File reads stay allow-default with the deny roots above. Every other category that has led to an escape is deny-by-default with an allowlist:

  • Writes: only the cwd, the spawn's own temp dir and runner state by default, plus the owner's sandbox.allowWrite entries, and the devices listed above.
  • Executables run only from the system roots (/bin, /sbin, /usr, /System, the Xcode tools, Homebrew, the Nix store), toolchain managers under your home (rustup, pyenv, nvm, the claude CLI's versions and others), the daemon's PATH and its bin prefixes, the daemon's own Node, its node_modules and its dependencies' read-only roots (Claude Code's binary in the SDK's platform package), the cwd and the spawn's own temp dir, and sandbox.allowExec. A program the child writes runs in the same sandbox, which is why the cwd and its temp dir stay allowed. This blocks starting other installed programs: apps outside /System, downloads, other checkouts.
  • Mach services: only nine exact names, each with its reason, such as directory lookups, FSEvents, TLS trust evaluation and logging. System services act outside the sandbox: LaunchServices opens apps, cfprefsd writes preferences that run code later, SecurityServer hands out keychain items. Add names with sandbox.allowMachServices.
  • Unix sockets: only mDNSResponder (DNS), $SSH_AUTH_SOCK and sandbox.allowUnixSockets. A socket belongs to a server outside the sandbox (tmux, Docker, editors) that would run code for the child.
  • Launching: lsopen and Apple Events to other apps are denied, so open x.app, Finder scripting and osascript cannot start anything outside the sandbox. job-creation is denied too, so launchctl submit, launchctl bootstrap and launchctl load cannot create a launchd job, which launchd would start unsandboxed and out of reach of stop. launchd itself stays reachable: every process holds its bootstrap port, so read-only commands such as launchctl print still answer. launchd checks the caller's sandbox before it creates a job.

Linux runs every child under bwrap. The filesystem is read-only except the write roots, and the deny roots are hidden. The child gets new PID and IPC namespaces and no_new_privs, so setuid helpers such as crontab cannot run. bwrap cannot filter connect(2) by path, so the spawn hides socket locations instead: an empty tmpfs over $XDG_RUNTIME_DIR (the D-Bus session bus that systemd-run --user uses, editor IPC, Wayland), /tmp/.X11-unix and /tmp/.ICE-unix and Docker Desktop's ~/.docker/desktop and ~/.docker/run, and /dev/null over the system Docker and Podman sockets, over every socket under ~/.colima, ~/.lima, ~/.local/share/containers and ~/.config/containers and ~/.rd (Colima, Lima, Podman machines, Rancher Desktop), over the LXD, Incus and libvirt sockets and the daemon's own $DOCKER_HOST socket, and over every socket up to two levels under the temp dirs (tmux, ssh-agent directories). A directory too large to search (over 2000 entries) is hidden whole and logged; inside a writable dir it cannot be hidden, and that is logged too. Allowlisted sockets are bound back. A Docker or Podman socket anywhere else (a custom DOCKER_HOST path, say) stays reachable on Linux unless you add its directory to sandbox.denyRead.

Every allowlist lives in src/sandbox/allowlist.ts, one entry per line with the tool that needs it and why it is safe. Widen them through config (sandbox.allowExec, sandbox.allowMachServices, sandbox.allowUnixSockets, or --sandbox-allow-exec, --sandbox-allow-mach and --sandbox-allow-socket), not by editing that file.

Stop reaches what an agent detached

stop signals the session's process group, then SIGKILLs it after the grace period. A process that leaves the group (a double fork with setsid) is handled per platform. viewport-daemon status and viewport-daemon doctor show which method is in use (Stop sweep), and serve logs it at startup.

  • Linux (namespace): bwrap is the daemon's direct child. Killing it kills the PID namespace's init, and the kernel kills every process in the namespace.
  • macOS (kernel): each spawn's profile denies reading its own marker file. After the grace, sandbox_check lists every process whose sandbox denies that marker, and each is SIGKILLed. The kernel does the attribution, so this survives a double fork, setsid and adoption by launchd. A process counts only if it is denied this spawn's marker and allowed its control file, runs as your uid, and is a known descendant or started after the spawn. Every signalled process meets all of these; a known descendant the kernel does not match is not signalled. Such processes are killed however many there are (in batches of 64, over up to 20 rounds that catch what forked meanwhile), so starting 65 processes no longer switches the sweep off. Two checks stop it instead: a match older than the spawn means the check itself is broken (only known descendants the kernel also matches are killed), and an attributed set of more than 512 processes, or more than half of your uid's processes, is implausible: nothing is signalled and it is logged as an error. Every signal goes through one function, which the test suite guards. It needs the Xcode Command Line Tools' python3, which calls libsandbox. An earlier version killed unrelated processes: see the postmortem.
  • macOS without the Command Line Tools (process-tree, shown as "best effort" by viewport-daemon status and viewport-daemon doctor): a weaker sweep. A poller remembers every descendant of the spawn by parent ancestry, every 250 ms, with start times (process groups are not used: their ids get reused). At stop, and when the command exits on its own, those still running are SIGKILLed. Any fast double fork beats it: a child that forks, setsids and has its parent exit within one poll is never seen. Treat this mode as cleanup, not containment, and install the tools (xcode-select --install) to get the kernel sweep.

Claude Code in the sandbox

Sandboxed Claude Code runs with its own config dir, ~/.viewport/state/<daemon>/claude-code, one per daemon home, set as CLAUDE_CONFIG_DIR after the session's own env. Your ~/.claude and ~/.claude.json stay read-only, so an agent cannot plant hooks, MCP servers, plugins or instructions that would run the next time you start claude yourself. At every spawn, your settings.json and CLAUDE.md are copied in read-only (a dotfiles symlink is copied as a file). The settings.json copy drops allow rules, defaultMode, extra directories, hooks, the status line, plugins and project MCP switches, and it is the only settings file Claude Code reads: project and local settings in the cwd never load, hooks and allow rules apply only from policy-tier settings the daemon pins, and no MCP server starts from disk. The directories Claude Code loads user-scope agents, skills, commands, rules and the like from are recreated empty and read-only (0555, and read-only in the sandbox) at every spawn, and CLAUDE_CODE_RESTRICT_PERSONAL_CONFIG=1 is set. See Approvals. Transcripts, todos and Claude's own .claude.json live in the daemon's dir, so resume works across sessions of one daemon.

Before every spawn, each directory from ~/.viewport down to that config dir must be a real directory owned by you, not a symlink, and the config dir must be 0700. Otherwise claude-code is unavailable, with the reason, because a symlinked state dir would make its target writable. Seeded files are recreated with O_CREAT|O_EXCL|O_NOFOLLOW, never written through a planted link. A source file whose real path lies in a deny root (a link to the daemon token, say) is refused, not copied.

Your claude login does not carry over. Claude Code names its keychain entry after the config dir, and the daemon never copies OAuth credentials, because a copied refresh token would fork and could log your own claude out. Set it up once:

  1. Run claude setup-token and copy the long-lived token it prints.
  2. Run viewport-daemon claude-token and paste it, or pipe it in (viewport-daemon claude-token < token-file, or --from-file <0600 file>). The token is read from stdin, never from the command line. It is stored 0600 in <home>/secrets/claude-code-token, which children cannot read. It is given to claude-code sessions only, as CLAUDE_CODE_OAUTH_TOKEN, and scrubbed from every other child's environment. viewport-daemon claude-token --clear removes it.

ANTHROPIC_API_KEY in the daemon's environment, Bedrock, Vertex and Foundry variables, and apiKeyHelper in your settings also work (they reach claude-code sessions under the CLI's minimal environment too; see Child environment). Without any of them, claude-code reports available: false with this fix (viewport-daemon status and viewport-daemon doctor show it), and session.start fails with daemon.runner_unavailable.

MCP servers do not load from disk: not your ~/.claude.json, not a project's .mcp.json, not the daemon's config dir. An MCP server is a process that starts without an approval, and those files are ones a repo or an agent can write.

session.start.env applies inside the sandbox only. The launcher is a fixed system binary, and LD_* and DYLD_* are refused before anything starts: on the wire, in supervisor.start() and in EnvPolicy.set. The daemon's own environment is passed through as is, since the daemon already loaded whatever it names.

macOSLinux
Backend/usr/bin/sandbox-exec with a generated profilebwrap (bubblewrap)
Read and write denyprofile deny file-read* file-write* on each real path, plus network-outbound to unix sockets under itan empty read-only tmpfs mounted over each root (/dev/null over a file)
Write allowlistdeny file-write* everywhere, then allow the roots, the spawn's temp dir and six device paths/ bound read-only, the spawn's temp dir at /tmp, then --bind for each root
Terminalsevery tty and pty node denied for reads and writes; a terminal session's own slave and /dev/tty allowed backa fresh /dev with its own devpts: no host terminal exists inside
Parents of rootswrite denied on each exact pathbound onto themselves (mount points cannot be renamed)
Missing rootspath rules cover a root created laterdaemon roots created 0700; others hidden by shadowing their parent
Executablesdeny-by-default, allowlisted rootsanything readable (setuid disabled by no_new_privs)
Mach servicesdeny-by-default, nine allowlisted namesnot applicable
Unix socketsdeny-by-default, allowlisted pathsknown locations hidden; abstract sockets and later sockets reachable
Launching apps, launchd jobslsopen, appleevent-send and job-creation deniednot applicable
Processesno PID namespace; signals only within its own sandbox, no task portsnew PID and IPC namespaces: the daemon is not in the child's /proc
Lifetimesandbox-exec execs the command (same pid); stop sweeps the spawn's sandbox--die-with-parent; a Node relay reports the command's real exit

Every rule uses real paths, so /tmp is /private/tmp on macOS and a symlinked home resolves. A deny rule always wins over an allow rule.

A terminal session on macOS starts through a short bash -p step inside its new pty: it asks the kernel for the pty's name (/usr/bin/tty on fd 0), accepts only /dev/ttys<digits>, writes it into the profile and execs sandbox-exec, so the pid stays the same. The slave is allocated by node-pty during the spawn, after the profile is written, so it cannot be known earlier. bash -p ignores BASH_ENV, ENV, SHELLOPTS and functions in the session's environment, so that environment cannot run code in this step, outside the sandbox.

On Linux a deny root that does not exist yet stays hidden if it is created while a child runs. The daemon creates its own roots (the daemon home and ~/.viewport/viewer) 0700 before spawning. A missing root inside a writable tree gets an empty 0700 placeholder. Any other missing root has its nearest existing parent shadowed: an empty read-only tmpfs over it, with the entries that existed at spawn bound back read-only. Entries created after the spawn are invisible to the child.

Interrupt, stop and Ctrl-C reach the command the same way on both platforms, and exit codes pass through. bwrap reports a signal death as exit code 128+N, so on Linux a small Node relay (the daemon's own binary) sits between bwrap and the command and records the real code or signal. Stop and interrupt signals reach the relay through the launcher's process group, and the relay forwards them. Without a terminal the command runs in its own process group, so each signal reaches it exactly once, through the relay. A signal that lands while the relay is still starting keeps the command from starting at all. If the relay exits early, it kills the command. The recorded status is advisory: the relay writes it in the spawn's own temp dir (its /tmp), so a sandboxed command can misreport how it ended, just as it chooses its own exit code. The daemon reads it after the process has ended, without following symlinks or blocking on a FIFO, reads at most 1 KiB with a strict schema, and falls back to the raw exit. Nothing depends on the label: session status, approvals and cleanup are decided by the daemon alone.

Fail closed, and the first-run fix

When the platform has no working sandbox, every runner reports available: false. The reason names the fix, session.start fails with daemon.runner_unavailable, and no session is created. Asking for --child-isolation home (or serve({ childIsolation: "home" })) explicitly makes the daemon refuse to start instead. Without that flag the daemon still starts and reports "home": no child can run outside the sandbox, because none can run at all.

  • Linux without bubblewrap: sudo apt-get install -y bubblewrap (dnf, yum, pacman, apk and zypper are detected too).
  • Ubuntu 23.10 and later, including 24.04, where AppArmor blocks unprivileged user namespaces: bwrap is installed but fails with setting up uid map: Permission denied. Run sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0 and persist it in /etc/sysctl.d/, or install an AppArmor profile that allows userns for /usr/bin/bwrap.
  • macOS: sandbox-exec ships with the OS. It fails only when the daemon itself already runs inside a sandbox, and nested profiles are refused.
  • Windows and other platforms have no backend yet.

Opting out

--child-isolation none, serve({ childIsolation: "none" }) or createSupervisor({ sandbox: { childIsolation: "none" } }) runs children unsandboxed. hello then reports child_isolation: "none" so viewers can warn, and serve() logs a warning at startup (process warning code VIEWPORT_NO_CHILD_ISOLATION). Under "none", agents can read the token and viewer keys.

To widen the policy instead of dropping it, use sandbox.allowWrite (a tradeoff, see above: prefer a per-project cache inside the cwd, such as CARGO_HOME=./.cargo-home or npm's --cache ./.npm-cache), sandbox.allowCwd, sandbox.allowUnixSockets (a unix socket or socket directory agents may connect to) and sandbox.denyRead. From the CLI these are --sandbox-network <host|none>, --sandbox-allow-write <path>, --sandbox-allow-cwd <dir>, --sandbox-allow-socket <path>, --sandbox-deny-read <path> (all repeatable) and --sandbox-deny-credentials on serve and up. Files given with --relay-token-file and --relay-viewer-token-file are denied automatically, wherever they live. None of these can remove a built-in deny root, and an allow root that would contain one is refused.

Credentials outside Viewport

The default policy protects Viewport's own trust boundary, not every secret your user can read. Under the default policy, agents can read:

  • ~/.ssh: private keys, config and known_hosts. Writes are blocked, so a first connection to a new host cannot save its key;
  • cloud and tool CLI credentials: ~/.aws, ~/.config/gcloud, ~/.azure, ~/.kube, ~/.docker/config.json, ~/.config/gh, ~/.npmrc, ~/.netrc, ~/.git-credentials, ~/.pypirc;
  • on Linux, the Secret Service keyring when its D-Bus session bus is reachable. The bus socket in $XDG_RUNTIME_DIR is hidden, but a bus on an abstract address is not. On macOS the login keychain is out of reach: SecurityServer is not an allowed Mach service, so a sandboxed process cannot read keychain items at all (which is also why your own claude login does not carry over).

These stay readable on purpose. Agents push over git+ssh, open pull requests with gh, publish with npm and call cloud CLIs. Denying these files by default would break that work, and people would turn the sandbox off entirely, which also exposes the daemon's keys. If your agents do not need them, set sandbox.denyCredentials: true (the list is CREDENTIAL_PATHS). Git over ssh then still works through ssh-agent (SSH_AUTH_SOCK), without key files. The agent socket is allowlisted, so an agent can have ssh-agent sign for any host, not only the ones your projects use. Add keys with ssh-add -c to confirm each use, or keep agent forwarding for trusted work only.

What the sandbox does not protect

  • The network, by default. With sandbox.network: "host" (the default, and what claude-code needs for its API), children can reach any host, and anything they can read they can send. That includes servers on localhost: a Jupyter server runs code for whoever has its token (often in its URL or a readable file), a browser's remote debugging port (--remote-debugging-port) drives your logged-in browser, and Docker over TCP (tcp://localhost:2375) is root in its VM. Unix sockets are filtered; TCP is not. Do not run such servers unauthenticated while agents run. For command sessions that need no network, set sandbox.network: "none" (--sandbox-network none). On Linux the child gets its own network namespace, with only a private loopback. On macOS every IP connection is denied, localhost included. The unix-socket allowlist still applies on both, so DNS lookups through mDNSResponder (macOS) and the ssh-agent keep working, and a DNS lookup can still carry data out. The setting is the owner's: no request or viewer can change it, and it applies to every session of the daemon, claude-code included, which then cannot reach its API.
  • Your projects. An agent can edit anything under its cwd, including code, git hooks, build scripts and the repository's .git/config, all of which you run later outside the daemon. .git/config is the quiet one: core.fsmonitor and core.hooksPath run a program on the next git status, including the one your shell prompt runs when you cd into the project. Review .git/config (and .git/hooks) after an agent session in a repo you care about.
  • Runner state. The daemon's Claude Code config dir is writable by its sessions, so one session can shape the next sandboxed one (transcripts, todos, .claude.json, caches). Its settings.json and its agent, skill, command and other definition directories are recreated read-only at every spawn, and hooks, allow rules and MCP servers written there do not apply. It never reaches your own claude. Temp is private per spawn; shared temp is read-only.
  • Leftovers after a failed sweep. On macOS without the kernel sweep (no Command Line Tools python3), a process that left the session's process group can outlive the session and keep writing its temp dir, even recreating it after the daemon removed it. Nothing else runs from there.
  • Credentials listed above, and on Linux a Secret Service reached over an abstract D-Bus address.
  • Linux abstract unix sockets, and sockets created after the spawn, under network: "host". bwrap cannot filter them without a network namespace, which also cuts TCP. A server listening on an abstract address (some D-Bus and X11 setups) stays reachable. Use --sandbox-network none to close abstract sockets.
  • Listening on loopback, on Linux. A pair link carries its secret in the URL fragment, and a browser sends the whole URL to the page that serves it, so whoever listens at the link's address reads the secret. Links use viewport://pair#... unless a Console URL is configured, so nothing on this machine receives them by default. On macOS children may never bind the Console's port (7071, and the configured Console URL's port) on any address. On Linux children share the host network under network: "host", and bwrap cannot filter bind(2): an agent can listen on 7071 or on your Console URL's port. If the Console URL points at this machine, keep the Console running before you open a link (a port it already holds cannot be taken), or paste the link into Console instead of opening it, or use --sandbox-network none.
  • macOS without the Command Line Tools: the stop sweep is best effort, and a fast double fork beats it (see above).
  • Debuggers. Task ports are denied (mach-priv-task-port), but attaching a debugger with Developer Mode on has not been tested inside the profile.
  • Docker and Podman on Linux through a socket outside the hidden locations (a custom DOCKER_HOST path). A docker command that fails inside a session with "Cannot connect to the Docker daemon" or "permission denied" on the socket is the sandbox working; add the socket's directory to sandbox.allowUnixSockets only if agents should control Docker, which is root-equivalent.
  • Other processes on macOS. There is no PID namespace. Measured on macOS 27: a child can read the command line of your other processes, including the daemon's, through sysctl(KERN_PROCARGS2), but not their environment. ps is setuid and refused inside the profile. No profile rule blocks argv without breaking ordinary programs (process-info-pidinfo crashes them). Never put a secret in a command line. The local token lives in <home>/token, which the sandbox denies. Keep relay tokens in a file inside the daemon home (--relay-token-file). If $VIEWPORT_DAEMON_RELAY_TOKEN is used, the daemon reads it once at startup and removes it from its environment before any child exists, but the process's original environment block cannot be erased. Token files given to the CLI are denied wherever they live; with the library API, add a token file outside the home to sandbox.denyRead. A child cannot signal processes outside its own sandbox ((deny signal) with same-sandbox allowed).
  • Substring scrubbing has limits. A child environment variable is dropped when its value contains a daemon secret verbatim. A secret that is encoded (base64, URL-escaped), split across variables or reached through a file path is not recognized.
  • A child that escapes the kernel sandbox. sandbox-exec is deprecated by Apple but still enforced by the kernel. bwrap depends on user namespaces.
  • Linux symlinked read-only entries. bwrap mounts over a symlink's target, so the link itself in a writable tree can still be replaced. The daemon's own read-only entries are real files.
  • Claude Code's own sandbox (sandbox.enabled in its settings) cannot nest inside the macOS profile. Leave it off for daemon sessions; the daemon's sandbox replaces it.

For agents you do not trust at all, run the daemon as a separate OS user, or in a VM or container.

Planned for v0.2: network isolation by default, with the network brokered by the daemon or the relay (an allowlisted egress proxy that lets claude-code reach the model API and nothing else), so that host stops being the default.

Pre-release check with the real Claude Code

The test suite covers the sandbox with real tools but never calls a model. Before a release, run the real Claude Code inside the sandbox once:

VIEWPORT_LIVE_CLAUDE=1 CLAUDE_CODE_OAUTH_TOKEN=<token from claude setup-token> make live-claude

It starts a sandboxed claude-code session in a temp project and asks it to write and read back a file. It checks for an assistant reply, a tool call and the file. A second session runs in a project whose .claude/settings.json and .claude/settings.local.json allow Bash, set defaultMode: "acceptEdits" and add a hook; it checks that an approval_requested for Bash still arrives and that the hook never ran. A third session runs after a subagent with permissionMode: acceptEdits was planted in the daemon's config dir; it checks that the file is gone at the spawn and that a write still asks. On macOS it then prints every sandbox denial the unified log recorded during the run, so a missing allowlist entry shows up before users hit it. The token goes only to the session's environment, is never stored or printed, and the check never runs in make check or CI.

Reporting

See SECURITY.md at the repository root.

On this page