Nativa PHP Core

Article

Sandbox and security ... how DSH confines processes

Article cover illustration: Security, dsh-series, deepseek, sandbox

A bash command runs. The agent reads /etc/passwd. No sandbox, no check, no error.

Why sandbox?

When an agent runs a bash command, it potentially has access to the entire disk. Without a sandbox, it could:

  • Read sensitive files (/etc/passwd, ~/.ssh/)
  • Overwrite configuration
  • Run malicious commands
  • See other users' processes

DSH solves this through a capability seam ... a contract (sandbox/seam) and implementations (sandbox-local/).

Three backends

1. Bubblewrap (bwrap): Linux

First it tries bwrap ... filesystem isolation:

# What bwrap confines:
bwrap \
    --ro-bind / /           # Entire host filesystem = read-only
    --dev /dev              # Fresh /dev
    --proc /proc            # Private-PID /proc
    --tmpfs /tmp            # Temporary /tmp
    --bind workspace /ws    # Workspace = writable
    -- echo "Hello from sandbox"

Key properties:

  • Read-only host root ... agent can't see real /etc, /home, etc.
  • Private-PID /proc ... agent can't see host processes (no magic links like root or fd)
  • Workspace-write ... only workspace and /tmp are writable

2. Landlock: Linux kernel

If bwrap isn't available, Landlock provides kernel-level sandboxing:

// Landlock is newer, more secure
// Works at kernel API level, not userspace tool
// Confines filesystem access at syscall level

Key properties:

  • Kernel-level ... no userspace tool
  • Available since Linux 5.13
  • May be partial on older kernels (confines only exposed access classes)

3. Seatbelt: macOS

On macOS, Apple's Seatbelt (sandbox-exec) is used:

# Seatbelt profile: allow-default + deny file-write*
# Only allows:
#   - /dev/null (read-only)
#   - workspace root (write)
#   - /tmp (write)
#   - os.tmpdir() (write)

Key properties:

  • Allow-default approach ... everything denied, explicitly allowed
  • deny file-write* ... no writes outside allowed paths
  • Apple marked sandbox-exec as deprecated but still ships it

4. Windows ACL (bonus)

Windows has its own restricted-token runner with per-workspace SID and revocable ACE.

Fail-closed ... no silent fallback

// If no sandbox backend is available:
// → SANDBOX_UNAVAILABLE error
// → Never silently falls through to unconfined mode

The agent never runs without a sandbox. If no backend is available, the operation fails.

Per-call policy

The sandbox isn't applied once ... every call has its own policy:

// read-only: agent can read, not write
await sandbox.wrap(['cat', 'file.txt'], { mode: 'read-only' })

// workspace-write: agent can only write to workspace
await sandbox.wrap(['edit', 'file.txt'], { mode: 'workspace-write' })

Enforcement completeness

Every wrap reports an enforcement level:

BackendEnforcementReason
bwrapfullComplete filesystem isolation
Landlockfull or partialDepends on kernel ABI
SeatbeltfullAllow-default + explicit deny
WindowspartialEveryone SID retained for process init

Cross-family integration

The sandbox integrates with filesystem seams:

// fs-sandbox ... filesystem provider with sandbox fencing
await root.plugin(FSLocal)
await root.plugin(FSSandbox)     // fences writes per sandbox mode
await root.plugin(ObservationPolicy)  // read-before-edit

Write/edit operations are fenced per sandbox mode:

  • read-only → write/edit rejected
  • workspace-write → only workspace + temp roots allowed

Runner selection

The backend is selected automatically:

1. Try bwrap → if OK, use bwrap
2. Try Landlock → if OK, use Landlock
3. If macOS → use Seatbelt
4. If Windows → use ACL runner
5. If nothing → SANDBOX_UNAVAILABLE

Selection is cached for the provider lifetime. Installing/removing a runner requires plugin reload.

Runner failure rules

Every wrap has structured runner-failure rules ... rules to distinguish:

TypeWhat it means
Broken sandboxRunner doesn't work (missing, not executable)
Command failureCommand failed (exit code ≠ 0, but sandbox works)
// Landlock: exit 125 + 'landlock-run:' fatal line = sandbox failure
// Landlock: exit 1, 2, 125 without 'landlock-run:' = child outcome
// bwrap/Seatbelt: signature-based detection

Custom runner

You can use your own runner:

# config
sandbox:
  runnerCommand: /usr/local/bin/my-sandbox-runner
  runnerFailureSignatures:
    - "my-runner: fatal"
    - "sandbox-error:"

runnerCommand skips probes and requires runnerFailureSignatures entries.

The solution was three backends with a shared contract. We replaced the monolithic sandbox with a seam pattern: sandbox/seam defines the interface, sandbox-local/ implements it. Fail-closed by default.

Sandbox remains the simplest security boundary, just not one you should skip. When you know what the agent can access, the policy writes itself. The next person who runs a command should not have to guess whether it's confined.

Summary

AspectDSH approach
Core principleFail-closed (never unconfined)
Backendsbwrap, Landlock, Seatbelt, Windows ACL
PolicyPer-call (read-only, workspace-write)
EnforcementReported (full/partial)
IntegrationCross-family with filesystem seams
CustomrunnerCommand + runnerFailureSignatures

→ Capability seams: how DSH abstracts abilities → DeepSeek Harness ... 50 packages: architecture overview → Cordis ... a deep dive: plugin framework

Sources

Comments (0)

No comments yet — be the first to react.

Reader questions (0)

No questions yet — be the first to ask.

Stuck on something in this article? Ask below. Your name is shown publicly; your email is never stored. A question appears here once a moderator approves it.