← All field notes
Security · 30 November 20268 min

Inside Castor’s zero-trust sandbox: 5 path layers, Landlock, and a 27-language AST gate

Giving an autonomous coding model shell and filesystem tools requires structural guardrails before the process runs, not prompt-level politeness.

Asking a language model in its system prompt not to touch /etc, ~/.ssh, or parent directories fails the moment a prompt injection or subtle path traversal slips into a repository file. An agent runtime that exposes filesystem and shell tools needs hard boundaries enforced in compiled native code.

Five sequential path verification layers

Every file read, write, or search call in Castor passes through five deterministic checks before opening a file descriptor:

  1. Canonical workspace root: Resolve the pinned project root at startup so relative assumptions cannot drift.
  2. Symlink realpath resolution: Follow every symlink target and verify the resolved physical path before access, blocking symlink escapes pointing outside the repo.
  3. Out-of-tree refusal: Reject any path whose canonical prefix exits the pinned workspace tree.
  4. Traversal normalization: Strip and collapse mixed separators, encoded dot-segments, and trailing components before prefix comparison.
  5. Binary sniffing: Prevent blind text reads or corrupt partial writes into compiled binaries and archive blobs.

Shell scanning, dead-man fuse, and Linux Landlock

Before spawning a shell child process, Castor parses the command lexically rather than relying on fragile naive regexes. Every spawned shell command runs inside a strict dead-man fuse timeout, and on Linux 5.13+ hosts, child processes enter a kernel-level Landlock confinement domain restricting filesystem writes strictly to approved workspace paths.

Pre-write syntax validation across 27 languages

A subtle failure mode in autonomous coding loops happens when an edit writes half a broken file and sends the agent into a multi-turn spiral trying to fix syntax errors it just introduced. Castor parses modified regions through a 27-grammar tree-sitter AST gate prior to committing edits, catching structural syntax regressions before they hit disk.

Across our 137-vector adversarial test suite covering traversal tricks, chained shell escapes, and out-of-tree symlinks, 123 blocked paths fail cleanly while the 14 legitimate workspace edge cases execute cleanly.

Inspect the full security specification →