Map: core / capabilities & sandbox

The grant mechanism in two halves: an in-process decision layer and an OS process sandbox that enforces it for external commands — each authoritative exactly where the other is blind ([[design/two-enforcers|two enforcers]]). Authority is attenuated by intersection — a grant block can only narrow.

The model — core/src/authority/policy/

authority::policy owns the resolved model and its judgments: GrantLayer (one layer, resolved), GrantStack (their dynamic composition) and the folds over it. A grant is authored as a grant value, a record decoded where it lands by shell::grant::decode_grant over decode_capability_map; authority::grant owns the freezing and all construction that reads the host, including the system reads (a-grant-is-decoded-where-it-lands). The in-process guard (core/src/authority/guard/) and the OS sandbox (core/src/authority/sandbox/projection.rs) enforce the resolved model (capability-is-data). Every judgment combines the layers’ evidence (authority-is-belnap-evidence); there is no meet of two layers into a layer (object-not-name). Why the grant value, the live judgment, and SandboxProjection are distinct and not one is argued in capability-carriers.

Submodules:

  • lattice.rs — the types and their algebra: GrantLayer, one layer in force, resolved where it was decoded (by shell::grant::decode_capability_map, the one walker, reached through decode_grant and decode_fragment, which Shell::decode_grant applies to a grant value from another host; freeze boundary), holding its rules and nothing beside them; GrantPath<R> { written, real }, a spelling and what its walk made of it, R an Extent (Everywhere, or Under { position, passed }: a position and what the walk passed on the way) for an allowance (Everywhere is the root spelling / on any host, or a Unix walk that reached /) and an Excluded for an exclusion; Net (Offline, the one opinion a layer holds on the network), Gpu (Withheld, the one opinion a layer holds on the GPU), the verb sets BTreeSet<EditorVerb> and BTreeSet<ShellVerb> (each Option: absent inherits), GrantStack (with push, remove, rehold), Meet, Join, Axis (join_top, is_top), Evidence { positive, negative } and Fragment, the extension file’s result (decode_fragment), consumed only by GrantLayer::extend (roles are types: a policy’s omitted axis is t, a fragment’s is ⊥). Behind cfg(any(test, feature = "test-util")), in authority/grant/builder.rs, sit the test builders Capabilities, ExecGrant (two BTreeSet<ExecKey>s, ExecGrant::of(allow, deny)), ExecKey::{Name, Path, Dir} and FsPolicy: Capabilities::value spells a GrantValue and test_helper::decoded decodes it, so a test grant meets the decoder’s refusals. No grant spells every program (no-grant-spells-every-program). GrantLayer::value is what shows a layer: its LayerValue, decode’s inverse, built from GrantLayer::axes through the typed encoder (a-grant-has-one-outward-form). Flag (Editor(EditorVerb), Shell(ShellVerb)) and GrantStack::permits(Flag) are the one verb vocabulary: membership, a meet over the layers, silence permitting. is_restrictive is the denotational activation predicate, each axis through is_top: exec unless Any with no exclusion, fs unless it writes Everywhere and excludes nothing, Net when Offline, Gpu when Withheld, a verb set unless it lists every verb;
  • table.rs — Table<A, D>, authority as two sets, allowances and exclusions (authority-tables): Allows (contains, own) and Denies (matches, answering a MatchedBy), supports, excludes, evidence (computed, never stored), live, withheld (a Withheld: MissingAllowance, or Excluded citing the exclusion that matches the least way), rehold_with, and Meet/Join for Table, exclusions joining and allowances meeting at their own subjects; the meet’s obligations and the generic law test are its property tests;
  • fs.rs — the fs instance: FsOp, FsAllow { Prefix(GrantPath<Extent>), RunPlace(RealPath) }, FsDeny(GrantPath<Excluded>), FsRules = Table<FsAllow, FsDeny>, and FsLayer { read, write }, the two tables a layer holds, each with every exclusion; region(stack, op, baseline), each supplying layer’s tables met (writing reads) and the system reads from Baseline joined; Baseline also supplies the bundled-tool image and protected boot identities, assembled in authority.rs, without a policy-to-sandbox dependency; ReadRegion, the one read table (run places P≤L included) folded once for a walk that judges many objects. GrantStack::judge and locate, each one function over the sealed path::Handle (Located or Dir), are where the stack’s evidence becomes authority: the pinned-binary veto (Refused::Guarded) first, then the fold, then the handle marked O, minted by Handle::judged against a Verdict only this file makes, as ReadRegion::judge and Ungoverned::{read, write} mint too; GrantStack::read is the read judgment, region(Read) alone;
  • exec.rs — the exec instance (authority-tables) and its judgment: Program (Tool or File { arg0, located }, one owned Located) and the Subject it is judged as (Program, Dir, Tool, Any); ExecAllow (Any, Dir, File, Tool) and ExecDeny (Name, Dir, File); ExecRules = Table<ExecAllow, ExecDeny>; rules, the stack’s table; places, the run places. Authored exec targets are resolved by authority::grant, not here; GrantStack::admit(baseline, program) judges the table then reading and is the only mint of Admitted (Program<Reading>, a private field); a refusal is data, ExecDenial::{Run(Withheld<ExecDeny>), Read(Withheld<FsDeny>)}, the refused program dropped; admit reads through read_region(baseline) and vouches for a file through ReadRegion::judge; it carries no argv. GrantStack::admit_name judges a failed walk’s Trace by the same exec table and GrantStack::read, without minting a handle. ExecRules::for_kernel is the table as the kernel holds it, KernelRules = Table<KernelAllow, ExecDeny>: KernelAllow (Any, Dir, File) has no tool, the kernel seeing ral’s own binary for one, and holds what its ExecAllow holds (a property test); with_support joins the live support as File allows; allowed_files the live file allowances the carriers are computed over. ExecDeny::matches is the one reading both tables give an exclusion. A veto (ExecDeny::Name(Veto)) keeps the name as written, which it shows, beside its path::command_name_key, which it judges and renders by;
  • deputy.rs — deputy_prefixes, the confused-deputy report: the prefixes a grant makes both exec-admitted and fs-writable, the live part of R ∧ W, the exec region (each exec layer’s Dir keys with full evidence, the root for every) met with fs::region(FsOp::Write), so each writable island under a runnable directory is named and a directory wholly excluded on either side is not. What it locates is where a write becomes runnable, not an escalation: within one projection the dropped binary is spawned under the confinement that wrote it, and only a runner outside the projection turns the shape into an escape — so it reports and never denies. Findings are recorded only into an open audit trail, as a layer is pushed (ral --audit --capabilities <profile> -c true; grant).

The shell::load module holds shell/load/profile.rs — load_capabilities_from_path / _from_str for .ral capability profiles, checked against Σ and run under Σ through evaluate_closed, with typecheck::table::declared(Form::Grant). It sees no session bindings and its helper lets never enter the session. A profile ends in grant’s options written out (SPEC §15.3): check_options checks each key during generation, recursing immediately into written exec: and fs: records. A bound or computed tail is T0077; an unwritten nested table is T0079. All profile keys are optional, so () or an empty file states nothing (the policy top, or an empty extension fragment). Runtime grant decoding retains shape, keyset and domain checks because it also accepts grants received as data, including wire grants and spawn restrictions.

The guard — core/src/authority/guard/

The model’s in-process enforcer: free guard::check_*(&GrantStack, …) functions fold the whole stack — a module boundary rather than a typestate (witness-collapse). It consumes resolved authority and returns domain data, never runtime values or control flow.

  • enforce.rs — the guards over the model’s judgments: check_exec (GrantStack::admit), check_exec_name (GrantStack::admit_name, a head’s failed-walk name judged as running it would be), fs_denial (projection of Refused::{Guarded, Withheld}), check_flag, and check_device_name. Exec checks return Result<_, Box<Denial>>; fs_denial returns Denial; flag and device checks return Result<(), Denial>. fact::Denial retains only the portable request and cause: no stored error, check, hint or missing-allowance flag. audit_check and missing_allowance derive their answers from those facts; describe and advice derive presentation. The judgment is reusable without the report: GrantStack::refusal_fs decides — Refused::Guarded first, for a write onto a boot-pinned sandbox binary (the supplied Baseline’s protected identities), before any grant is folded: the empty stack is exactly the case that veto must catch. GrantStack::admits_fs is the quiet twin a write asks before reading its before- and after-images.

The shell adapter — core/src/shell/runtime/state/checks.rs

  • impl Shell: check(Flag, who), exec_refused, baseline, locate, locate_dir, locate_existing, locate_if_admitted (each excusing the discard device LexicalPath::is_discard and refusing a reserved device name before either region is consulted), judge (an object a caller already holds), admits_fs, sandbox_projection, and the grant scope guards (with_layer, push_session_capabilities, audit_deputy_prefixes, has_active_capabilities). Shell::locate is the one path every read and open takes: the device-name refusal, then GrantStack::locate (path::walk to the object, GrantStack::judge on its transcript), handing back the handle vouched for. Shell::refused records the selected denial’s derived check through Shell::record_check with no Mooring, so on the trail alone, then mints Reason::Denied and its Break. Shell::exec_refused, taking the Denial that guard::check_exec or check_exec_name returned to a head or test_access, records an exec refusal against its call’s Mooring and mints its Break. GrantStack::judge_failure judges failure_trace for the requested operation before an error is disclosed; GrantStack::locate applies it for every caller and either handle kind, and locate_existing judges failed walks through it.

Construction — core/src/authority/grant/

authority::grant owns freezing, directory selectors, authored resolution and host system-read discovery. It builds the resolved model that policy judges, without naming a shell or runtime value; the Value decoder and spawn adapter live in shell::grant.

  • paths.rs — Polar and grant-path walking: allowances keep positions, exclusions hold objects;
  • resolve.rs — Keyed and name_rules: how a walked exec target becomes the rules a layer holds, by polarity, including PATH lookup;
  • value.rs — the grant value as typed data: Axes (ExecTable, FsTable, Target, Place) encodes to a GrantValue, the only way a host spells one, and GrantValue::deny_all is the value that withholds all positive authority;
  • builder.rs — the test builder over Axes (Capabilities, above);
  • host.rs — Baseline::of_env/of_home: the system reads toolchains::system_reads_in keeps, as prefixes, refusing with an Error (hint kept); authority.rs attaches the sandbox’s boot pins to form the runtime Baseline;
  • freeze.rs — the one place a grant’s Place or Selector becomes a FrozenPath (a folded spelling, which decode then walks), against one anchor: FreezeCtx::at (an owned environ::EnvVars and CwdPath: the Resolver pair, with optional scratch) and its place (None is a dead grant, an absolute payload classified on the raw string by live_absolute through lex::grant_eligibility (EligibleOn / GrantRefusal) over lex::parse_bytes: a HeadKind::Device or HeadKind::Malformed head, a mixed-separator opening (/\x, \/x, GrantRefusal::MixedHead) included, is refused first, though Windows reads it as absolute; a \??\ NT object-manager head (HeadKind::Driveless with Namespace::Object, GrantRefusal::NtObject), read as Win32 reads it, is refused under every tag with its own refusal; then HeadKind::Posix is EligibleOn::Posix, a non-verbatim //srv/sh share is EligibleOn::Both, and a HeadKind::Drive or other HeadKind::Unc, a verbatim root included, is EligibleOn::Windows, dead under POSIX) and selector; host_absolute, the one classifier of a path the host holds or chooses (exarch’s carve-outs, PATH entries, toolchain and system-read directories), classified on its native text and frozen as an absolute grant, refused with GrantRefusal::ForeignOrRelative where a payload would be dead, so exarch’s deny layer fails closed, in words about the path alone: its caller names who chose it, and only a payload’s refusal (live_absolute) adds, as a hint, how a grant writes it; the tags absolute, cwd, home, tempdir, scratch, gitdir and xdg-*, the root-program refusal root_program, the gitdir refusals (bad_pointer, from BadPointer), Selector (Path | Toolchain(Toolchain)) and the path selector (path_dirs_in, which classifies each absolute PATH entry raw, as an absolute payload, before the freeze folds it), and refuse_the_world, the guard both it and every kept toolchain directory call, over the_world, the one predicate for a root, the home or an ancestor of it, which system-read discovery uses too; FrozenPath::freeze refuses a path that is not Unicode;
  • toolchains.rs — the directories the host chooses, as one table: enum Toolchain (system and the package managers), each a few Locations of overrides and defaults, from one exhaustive match, and LISTED, each platform’s system reads no selector names, Locations too (Windows’ are %SystemRoot%, %ProgramFiles% and %ProgramFiles(x86)% as overrides). chosen selects over an injected host environment and home; walked, the one walker of chosen directories, holds each by host_absolute (a malformed one refused, naming the variable or default and what would hold it), walks it by GrantPath::walked and drops the absent. expand_in keeps the directories and checks each followed trace against the world, naming either its override or its default spelling in a refusal (Chosen::subject), before W::grant retains the allowance position or exclusion objects. FreezeCtx::selector calls it with the freeze’s environment, overlay then host (FreezeCtx::var), the one environment a bare name, dir pathand every toolchain selector read, so aPATHan overlay sets governs all three; the publicexpandwrapper returns the surviving spellings as nativePathBufs. system_reads_inwalksLISTEDand the rows ofSYSTEM_READS (homebrew, macports, nix, pkgsrc), keeping what exists, a file included, outside the process's home and the_world (keeps_system_read`) (grant §Selectors states the rules).

Runtime decoding — core/src/shell/grant/

shell/grant.rs supplies Shell::freeze_ctx (env, logical cwd and scratch) and the Error → Break conversion; substantive freezing stays in authority::grant::freeze.

  • decode.rs — decode_capability_map, the one grant walker (crate-private), which reads a grant [...] / --capabilities Value map into a resolved GrantLayer; decode_grant and decode_fragment are its public entries for a grant value one host authored for another (Shell::decode_grant, in shell/grant.rs, applies it against the receiving shell’s anchor), one dimension decoder per exec / fs / net / gpu / editor / shell key, nested tables and verb lists read as sets — every one of them authority, none of them a recording switch (audit). Its exec targets freeze and walk through authority::grant directly into exec rules: a dir selector expands once per directory, a bare name reads the decoding environment’s PATH, a path allowance holds the position its walk reached, and an exclusion the objects held;
  • spawn.rs — SpawnGrant (Inherit, Base, Restrict), a spawn’s grant as it crosses to a child that has not yet resolved it, frozen against the child’s own FreezeCtx through Shell::freeze_ctx; GrantNarrower is the host-supplied fn(&str, &FreezeCtx) -> Result<GrantLayer, Error> that resolves a named base.

Path resolution

Path resolution is core/src/path/: lexical stages, then one walk, plus which.rs for PATH search. path.rs’s doc names every module. An item used outside path/ has one path, crate::path::Item, re-exported there from a private module; the public modules tree (tree::Walk, tree::Glob, tree::bytes), git (git::Pointer, git::work_tree_chain) and complete (complete::PartialPath, complete::TildeReading) are namespaces, whose items are named through them and re-exported nowhere.

  • expand — sigil.rs (run-time ~ and xdg: expansion of ordinary paths, never in a grant; the places cwd, tempdir, scratch, gitdir are policy-only, expanded at freeze by grant::freeze (scratch against the spelling of the session’s scratch that the FreezeCtx carries, which plain ral has none of); git.rs backs gitdir discovery, following a .git pointer file only to a git directory whose gitdir back-pointer or core.worktree names the working tree back, judged by the positions the two walks reach, never by identity; a bad pointer is a path-level BadPointer, phrased as a grant error by the caller), tilde.rs (~ and ~/sub only; an unset HOME is None, and each caller picks its own honest answer; TildePath::shown is the one spelling ~, home and a ~/… command head share, and TildePath::expand the path such a head runs, the suffix read onto an exact verbatim home by verbatim_joined). The expansion expand_path_prefix answers is native, in the host’s own spelling, for the resolver to hand on to the OS. sigil::SigilHead is the one reading of a path’s head — Tilde, Xdg, or UnknownXdg (an xdg: no kind answers to, passed through literally) — that expansion, literal_relative and a grant’s refusal of a sigil all ask. An xdg: sub-path naming a volume of its own under Windows rules — a drive component, or a share or namespace head opening it — would re-root the join, so expand_path_prefix leaves the whole path as written: it fails closed, a prefix matching nothing rather than a fabricated path, while a grant refuses the gap outright in grant::freeze;
  • lex — lex.rs, the one surface over lex/, split by concern: head.rs (the parser and every head judgment, and windows_components, a path’s names past windows_head, the one split every Windows identity takes), eligibility.rs (grant_eligibility, classify_subpath), anchoring.rs (anchor, and anchor_on for a caller that may have no cwd: PATH entries, git pointers). Anchoring uses native separators in a relative suffix and leaves its dot components and absolute inputs as written, except onto an exact \\?\ verbatim drive or share, past whose head Win32 hands the kernel / as a name byte and ./.. as names: there fold::verbatim_joined reads the suffix as Win32 would — either separator splits, . and empty names drop, .. takes a name of the base but never its volume, a trailing separator stays — and a root-relative \x joins the volume’s root. Every composer that appends a Win32 suffix to a possibly-verbatim base goes through it: anchor, TildePath::expand and join_relative (so xdg:). fold.rs, join.rs, name.rs (a path’s names by spelling: file_name, spelled_parent, extension, utf8, relative_key and its inverse key_within) and command.rs (names_a_path, the Windows exec extensions, is_batch_image). One structural parser, parse_bytes, reading a byte slice under PathRules into Parsed { raw, rules, kind: HeadKind, spelling: HeadSpelling, head_len }, from which resolution, ./.. folding and every head judgment project. HeadKind names the structural head (Posix, Drive { letter, volume }, Unc { volume }, Driveless, DriveRelative { letter }, Relative, Device for \\.\, and Malformed for a two-separator or \\?\ head that is no well-formed drive, share or device); HeadSpelling records the opening separator and namespace facts once (namespace: Option<Namespace> — Verbatim { exact } for \\?\, Device { exact } for \\.\, Object for \??\, with exact / Namespace::is_exact true when all three separator bytes of that 4-byte prefix are \ — mixed_opening for /\ or \/, and opens_with_slash). fold_dots_under (over fold_bytes) is one kernel under either rules from any host, fold_dots its host instance on a held path: head_len marks where the head ends and only the names past it fold, joined with the rules’ separator, so a fold preserves HeadKind, volume and (save when .. climbs into the ?? component of a \??\ driveless path) HeadSpelling::namespace; under Windows rules a non-namespace Drive, Unc, Driveless, DriveRelative or Relative head (Parsed::respell_head) is respelled with \ too (C:/a/b folds to C:\a\b, //srv/sh to \\srv\sh), so such a path has one separator throughout, while every head whose kind or meaning turns on its spelling is kept as written: a Posix / (as \ it would be Driveless), a slash-spelled verbatim head (//?/C:/x is a device path Win32 normalises, so its tail past head_len folds), and a Device or Malformed path, or an exact \\?\ verbatim path (Namespace::is_exact, head_len == raw.len(): Win32 hands its rest to the kernel uninterpreted, / a name byte and ./.. names), all head and kept whole, .. included; a relative path’s drive-shaped first name keeps a .\ before it; is_unparsed_head, a Windows path absolute to the kernel in which std::path finds no prefix and so would descend or climb from the current drive, which the walk refuses. Every head predicate projects from parse_bytes: whether a path is absolute under either rules set (absolute_under / Parsed::is_absolute: POSIX, HeadKind::Posix; Windows, Drive, Unc, Device or Malformed) and on this host (is_absolute, absolute_under the host’s rules, the one absoluteness ral asks, anchor included; Path::is_absolute is banned in clippy.toml in its favour); is_working_directory (Posix, or Drive / Unc under Windows); is_bare_root (one separator alone under the given PathRules); has_drive (non-namespace Drive or DriveRelative); Parsed::is_mixed_head and Parsed::is_nt_object, shared by grant_eligibility and classify_subpath (SubpathRefusal), which grant::freeze maps to its messages; is_network (HeadKind::Unc), is_verbatim_drive (Namespace::Verbatim + HeadKind::Drive) and is_volume_guid (has_os_namespace_head with a Volume{ namespace_tail), which the Windows DACL backend asks rather than parsing prefixes itself; Parsed::has_os_namespace_head (Namespace::is_exact), what show leaves unfolded; Parsed::without_verbatim_prefix, what the Windows identity fold slices; and Parsed::namespace_tail, what the discard device check reads under HeadKind::Device; utf8, a path’s native spelling as text or NotUtf8 naming it, the one strict conversion for a path that must travel as a string (--capabilities profiles, SourceFile), as shown is the one lossy conversion, for display only; spelled_parent, a path with its last name dropped by spelling alone, for a program’s own layout (the folder a file it writes sits in, its install tree, a run folder it made) and never for a name a grant judges, which asks RealPath::parent; a final component’s extension; relative_suffix strips a sub-path’s leading separators under the rules, and join_under joins a sub-path onto a base string one component at a time with the separator of the given rules, on every host alike (GuestPath::join is it under Posix rules), and refuses (Rerooting) a sub-path naming a volume of its own under Windows rules — absolute there, or a drive at any component; join_relative is it under the host’s rules onto a host-held path, and join_slash is that for a /-separated constant subpath the program spells, panicking if one re-roots; identity.rs: name identity and containment, a command name’s command_name_key, and windows_collision_key naming a kernel object by an absolute path under collision_key per component, coarser than NTFS’s own fold so a lock merges every spelling NTFS equates; device.rs: device names, and win32_trimmed, a final component with the trailing dots and blanks Win32 drops, the one copy of that rule (reserved device names, batch images);
  • complete — complete.rs, the path half of completing a typed word: PartialPath splits it, under a TildeReading (home, or a literal ~ inside quotes), into the directory to list and the needle, says which entries are offered, and spells a chosen one back as ral shows a path (typed ~ kept, /-separated; expanded via TildePath::shown only when the spelling must be quoted);
  • slug — slug.rs, project_slug: a launch cwd as one directory-name component, for keying per-project state. It is a readable part (/Users/x/proj → -Users-x-proj, lossy, for a person scanning a listing), a -, and 16 hex digits of the SHA-256 of the cwd’s exact OS bytes (UTF-16 units on Windows), so two cwds that differ at all key apart: -Users-x-proj-25cf7293a3713b73;
  • canon — canon.rs, the names one object answers to for the kernel sandboxes: firmlink twins (twins), which render.rs renders as rule text (render_real, refusing a name that is not UTF-8) and whose ancestors it takes (proper_ancestors); what an object is, and where a spelling reaches it, is the walk’s to say;
  • locate — handle.rs exports one resolver from handle/: names.rs validates spellings, trace.rs holds evidence, and exclusion.rs keeps deny anchors. object.rs owns private handles and authority conversions; operations in object/, traversal in resolve.rs, and host adapters are its child modules. object/write.rs::create_scoped_dir creates a secret directory through a write-judged absent target; ScopedDir holds it and permits only empty-root rollback on drop. Recursive cleanup (Located::remove_all) requires a fresh write judgment of cleanup_target, the actual held tree, not its original absent name, and of every descendant before it is entered or removed. A refused descendant stops the removal and stays, with its ancestors; an I/O failure names the entry it happened at. create_writable_file exclusively creates a secret or public regular file without requiring read authority. Scoped creation validates physical Unix ancestors through held .. handles: current-user/root ownership, no group/other writes unless sticky. Linux POSIX ACL permissions are bounded by the mode’s group mask; macOS additionally refuses extended ACL entries. Windows holds parents without delete sharing, proves a safe owner/ACL inheritance chain to a protected boundary, then revalidates top-down. The opened workspace is checked too. Windows secret directories use protected, inheritable owner-only DACLs; replacements and editor backups inherit privacy. This cross-user proof excludes same-user or privileged interference and retained attacker WRITE_DAC/WRITE_OWNER handles granted by a formerly unsafe Windows ACL: changing a DACL does not revoke existing handles. walk descends from the root through directory handles with no symlink followed by the kernel, splicing each link into the name itself (a link’s target read through the handle held on it), and hands back a Located — the directory handle, the leaf, and the Trace whose RealPath is symlink-free and whose passed names each link whose target it read and each directory a .. climbed out of — whose every operation is handle-relative. A held link never reads a replacement’s target: if the filesystem refuses its read after unlink (APFS on macOS 26), the read refuses rather than looking the name up again. Each step is one host primitive, step, reading the child’s stored name and identity from the handle just opened (Linux the name openat resolved, macOS the parent’s listing for that identity, Windows the normalized name checked against the parent’s path). A .. is physical, the kernel’s rule, even from a link target (the user’s own path keeps its logical fold); the splice count is bounded by MAX_HOPS. handle/error.rs::failure_trace, exported by handle.rs, takes loop_trace’s actual failed-link transcript from a spent-budget error, else walks the name leniently with LeafMode::Follow. The fs doors judge it for their operation, heads for running, before disclosing the error. Every restart, the given name and each splice alike, is put to one rooted check, so a link target relative to a drive’s current directory or with an unparsed head is refused as the name itself would be. walk_dir, walk_lenient (a grant spelling’s transcript, as far as the disk goes), walk_excluded (an exclusion’s Excluded, the link and its target held) and open_discard are the other entries; Dir, Located and Hold are the three holders and Unjudged, Reading, Writing and Installing who vouched (path-judgment);
  • match — identity.rs: RealPath::contains, an allowance by position, names as stored (on Windows windows_stored_components, preserving stored case and unifying / vs \, and \\?\-verbatim spellings), and Excluded::matches, an exclusion by position under collision_key (compatibility caseless matching of the uppercase image, ICU4X, the coarsest identity any filesystem gives a name) or by the object its walk held, answering a MatchedBy (denies-hold-under-every-spelling); the form-blind path_within is private to the file;
  • name a device — device::is_discard_device, behind LexicalPath::is_discard: /dev/null, or on Windows exactly the device-namespace spelling \\.\NUL (either slash, any case), and no other path. Every other Windows path whose last component is a DOS reserved device name — NUL, CON, PRN, AUX, COM1–COM9, LPT1–LPT9, COM¹–COM³, LPT¹–LPT³, any case, any extension, trailing dots and blanks trimmed — is refused, not excused: device::reserved_device_refusal phrases the error (for NUL, as the question “did you mean \\.\NUL?”), and guard::check_device_name asks it at the fs entries, Shell::locate and its siblings, ahead of any grant. A resolved path keeps its last component, so the check needs no raw spelling. Like the identity rules above both take windows as a parameter rather than reading cfg!, so neither table is dark on the other host.

resolver.rs composes the stages — Resolver::resolve and Resolver::anchor are the sole constructors of a LexicalPath (forms.rs, with its grant-side twin FrozenPath), so a walk cannot run before lexing: the ordering is in the types, not convention. resolve takes surface text and expands sigils first; anchor takes a path the host already holds, a walked entry say, and expands nothing, so a file named ~ stays that file and a non-UTF-8 name is never renamed by a string round trip. path::spelled anchors a host-held path against the process’s cwd with Resolver::anchor, returning a sentence if that cwd is unavailable. A Resolver is a environ::EnvVars and a CwdPath: ~ reads env.home(), xdg: the XDG_*_HOME of env through get_or_host, so a within [env: …] overlay reaches both. Resolver::at builds one for a caller with no shell to mint one; resolve_in_script is resolve for a path written in a ral script, which reads it beside itself: it is resolve itself with the script’s directory for the cwd, so the two agree: sigils expand first, only a still-relative result joins the script’s directory, and an absolute one, a malformed head included, is kept as resolve keeps it, never lent the directory’s drive. The directory is the native parent of the file’s SourceOrigin, never a re-parsed rendering of it, anchored as anchor takes it, so a script under a directory named ~ stays there. A virtual source has no directory, and its paths resolve against the cwd.

A module read has one candidate: the path written at use. The loader resolves and judges it with shell.locate at check time, using the containing file as anchor (the session cwd for a virtual source), check-time environment for sigil heads, and the grant then in force. No surrounding within or grant, or earlier cd in the unit, changes that read. The lexical grant still governs the module’s runtime effects. A denial is stamped at use and survives in the dispatch trail on static refusal. --check boots and applies profiles before taking this same compile path. ral reads no RAL_PATH; plugins likewise name one file (plugins).

tree.rs is the one directory-tree walk, tree::Walk: ral enumerates, with Dir::read_dir and Dir::open_dir, depth first in name order, and ignore only matches (tree/ignore.rs is the rule engine over ignore::gitignore, opening nothing). A Walk is told what it may enter (respecting_ignores; work_tree, which keeps dotfiles but skips every .git; all; or search, the walk every search reads: ignore rules kept, or with hidden all but .git, on one file system; a depth; link following; a Filter) and which region it may read (readable_by), judges every directory it enters, every file it reads for its own guidance and every entry it yields against it, polls the cancel scope at each entry, and yields WalkEntry { shown, names, found }, which tells a pruning from a refusal from an entry unseen. A Filter is an automaton the walk runs: its State is carried from each directory’s frame down to its entries (step drops an entry with all beneath it), and yields and enters decide the rest. () is no filter, and a predicate on an EntryName is one by a blanket impl. The root comes first whatever the filter says, which decides only whether it is entered. Entries append through LexicalPath::join, preserving the parent’s spelling, including dots in Windows verbatim paths; PathBuf::join would normalize those away. An entry carries its names beneath the root (names), and no reader takes shown apart to recover them: WalkEntry::key slash-joins them (synod’s manifest keys), and WalkEntry::name follows the root’s cwd-relative spelling with them, or with none is absolute, returning Result<String, path::NotUtf8> with no runtime types. A relative name is never the entry with the cwd stripped off: a verbatim cwd (\\?\C:\d) folds .. as Win32 reads it, so ..\x anchors to a path the cwd no longer prefixes. Relative names omit a leading . name but retain .., and the root spelled . or nothing is .. A name reads back as itself: one a sigil would claim is spelled ./~/x (sigil::literal_relative), and one no ral string can hold is refused (path::to_text).

tree/glob.rs is glob’s pattern language, a Filter. Glob::parse lexes the pattern as a path is (parse_bytes): its head and the names before the first wildcard are the prefix, kept as written (never reassembled by PathBuf::push, which re-roots on a drive name and folds verbatim ..), and a head the lexer reads whole (exact verbatim, device, malformed) is the whole pattern. Past it, . names drop, .. is refused, and each name is a literal (matched byte for byte), a wildcard (globset, never a hidden name) or **. A name the pattern follows with a separator is a directory: a trailing separator, or a ** after the name that matches nothing, asks for one (Filter::yields is told is_dir, a followed link included), so a.txt/ and a.txt/** match nothing. The glob’s state is how the entry matches (Match: by its name, or as a directory) and the steps a name beneath it may take; ** never passes beneath a link, though it names one, and a link another step takes is passed through. The root matches only where the prefix spells it, so no match is named by nothing.

Shell::admitted_walk (shell/runtime/walk.rs) wraps a walk beneath a path as AdmittedWalk: Resolver::resolve_named gives the root and, after one ~/xdg: expansion, its spelling where that reads against the whole cwd (Windows \x and D:x give absolute names); Shell::locate_existing asks the grant of the root, so a denied root, there or not, is refused and an absent one is None; it selects the live region and scope, raises a root the walk could not see or enter, skips unseen entries beneath it, and converts cancellation to a non-catchable stop and naming failures to contextual errors. glob takes None as no match; Shell::walk_beneath, which exarch’s grep-files, grep-hidden, find-files and explore-dir use over Walk::search, takes it as NotFound.

which.rs is the one PATH walk. Its anchor is an Option<&CwdPath>: the shell’s cwd cell, or None for a shell-less caller — and CwdPath has one constructor, so no call site can choose “here” for itself.

  • names_a_path (lex/command.rs, with the rest of the command-name lexing) is the one answer to “is this command name a path?”: it bears a separator under the host’s PathRules (PathRules::is_separator: / everywhere, \ under Windows alone), so off Windows a\b is a bare name for PATH. names_a_path_for takes the rules, and the lexer’s Word::Path, ir::CommandName::of, the walk itself and the grant decoder’s `name check all ask it.
  • path_dirs is the sole directory list behind locate and search; it drops empty PATH elements on every platform, so a trailing ; or : never means the cwd. . and ./bin are honoured, as written. locate_in is a Linux-only, unmemoised search over directories a caller already holds (path_dirs(…, None) for bwrap’s pin, absolute entries alone), so no list is re-joined into a string to be split again.
  • search walks every candidate in PATH order at most once and hands each walk, a Candidate, to the judgment; none with no PATH. The memo’s Answer remembers the first candidate whose walk found a program (Located::holds_program, the one executable predicate), an undisclosed ordering hint: that candidate is walked first and judged at its PATH place. locate is the unjudged fold of the same walk. prepare reads the judged fold’s verdict without probing.
  • On Windows, %PATHEXT% suffixes append: build.ps1 yields build.ps1, build.ps1.EXE, …, never build.exe.
  • Grant construction walks the PATH of the decoding environment with no anchor, so neither a scoped PATH nor a relative entry can redirect a bare key.

A FrozenPath (forms.rs) is a spelling and nothing else: folded, shown, ordered. What it names is the walk’s to say, once, when the layer is decoded: GrantPath { written, real }. Every authority is judged on `real`: RealPath::contains for an allowance, Excluded::matches for an exclusion — and no other way: path_within and its string twin are pub(super) to identity.rs, so the form-blind kernel does not leave core/src/path/, and outside the module a spelling leaves the type only as a string (as_str, into_string) for rendering. That is enforced rather than documented because the xdg-* freeze guard once chose the form for itself — asking on the surface while the check it guarded matched the real form — and read a symlink out of HOME as contained.

The set-level algebra over prefixes is not in path/: it is authority::policy::table, which names polarities and never identities, so every spelling question stays here. RealPath (handle/trace.rs) is the position a walk ends at and the identity of a run place, ordered as the host identifies files.

XDG base directories resolve through one resolver, path/basedir.rs (XdgKind, the pure resolve_xdg_in; host::xdg reads the host env, the xdg: sigil and the freeze an EnvVars; app_dir spells an application’s own $XDG_<kind>_HOME/<app>/ for ral and exarch alike): an absolute XDG_*_HOME override else the home-joined Linux default on every platform, and None where there is neither — a host fact answers with an Option, so each caller picks its own fallback rather than inheriting a fabricated home. For the program’s own layout alone (host::xdg, host::layout_home and host::home_dot) the home falls back, where no HOME is bound, to the account’s own from the user database (the AccountHome site), so app_dir, OwnDir, UserFile and the credential denies all see the same base; a ~ in a script (host::home) is unchanged. Where even that fails, own refuses with an error naming what to set, and no temp dir stands in. Both the xdg-* grant places (sigil.rs, grant::freeze) and the host’s own config/data loaders (host::xdg) defer to it, so a grant and the rc/history/plugin paths can never name different directories — xdg-resolver-consolidation.

The files a program touches on its own account, outside any shell, are core/src/own.rs’s, under one authority, the crate-private write side of authority::policy::Ungoverned:

  • OwnDir — what the program keeps for itself (state, tokens, logs, caches, records, scratches): a held directory reached from an XDG root, one entry name per operation, no link followed beneath it;
  • UserFile — a file the user writes at a place the program chooses (the rc, config.ral, house rules): links followed, a replace staged beside the link’s target so the link survives, seed writing only where nothing stands;
  • read_named, read_named_source, open_named, kind_named, create_named — a file the user names, the one write being a new file. read_named_source returns text and the real path of the same held object, fixing a script’s identity before boot can change cwd. They take any path, so clippy.toml bans them, and each caller is a typed site that says why the name is the user’s: a CLI argument, a TUI command, the install tree.

own/site.rs holds two authority-mint sites, Silent::{Read, Write}, for clippy-banned Ungoverned methods, but no syscall sites: each syscall it needs is a walk primitive (walk_dir_made, Located::{remove, rename, open_data}, and Visibility’s Public, Private and Secret). The config home holds only what the user writes (own-files).

OS sandbox — core/src/authority/sandbox/

External commands inside a grant block run under an OS sandbox enforcing the declared filesystem and network capabilities — and exec, wherever a backend carries the allow-list into the kernel, so a grant whose only opinion is exec engages the sandbox too (sandbox::EXEC_ENFORCED, the one statement of that fact, read by SandboxProjection::of). Exec is guarded in-process on every platform (guard::check_exec) before the spawn; both Unix backends additionally render the same rules into the kernel, catching the re-execs the in-process guard never sees (sh -c, find -exec) — macOS as Seatbelt process-exec forms, positives then negatives, Linux as a Landlock Execute ruleset the payload enters inside the bwrap envelope over admits the parent opened in the host (linux/landlock.rs; Landlock being allow-list only, a deny inside an allowed directory is subtracted from it, entry by entry over the tree at launch; Any lowered against the bind plan, which is computed before the ruleset). carriers.rs computes the live support the kernel must admit beside the table for a script to start, under any confined launch whose fs or exec is restricted: system-vouched #! interpreters and macOS shims, by trusted_real — regular files only, judged against the effective uid — never env’s target (exec-carriers). The AppContainer on Windows has no path-exec filter, so there the in-process guard stands alone (the deny-by-default fs projection still bounds which images a child can read, and so load, at all). Exec-deny ACEs and directory execute/traverse semantics remain unimplemented. Native Windows verification of stored-case walks, verbatim image launch, launch refusals and handle-inheritance serialization is outstanding; cross-compilation alone does not establish them.

Pathname Unix sockets outside a host envelope follow stated fs writes: linux/landlock.rs handles REFER | RESOLVE_UNIX on every ABI >= 9 launch, adding EXECUTE for a restricted exec; directory writes are lowered onto the bind roots and file writes admit the opened file alone. bwrap masks fs denies. macos.rs::emit_fs_restricted emits outbound, bind and inbound socket clauses per write name and the corresponding denies afterwards. Unrestricted fs admits no outside socket, so exec-only, net-only and gpu-only grants admit none via fs. The macOS resolver additionally rides net; Linux admits no resolver socket and falls back to DNS over IP. Below ABI 9 every pathname socket a bind shows remains reachable, even offline (the ABI migration). A sibling launch needs a write covering the server socket. A write covering a deputy admits it, and a writable foreign socket can be unlinked and replaced to intercept later clients; the five restrictive bundled profiles write only cwd, gitdir and scratch. exarch’s $TMPDIR is $EXARCH_SCRATCH/tmp: hardcoded /tmp is per-command memory on Linux and refused on macOS. unix-sockets-follow-writes records the policy and its limits.

Inside a guest, ral-guest starts the engine as --guest-engine <cgroup-root>, named by guest_abi::layout::ENGINE_FLAG. The daemon and jail share layout::EXEC_CONTROLLERS. The role installs the spawn jail, so Command::prepare (shell/exec/command.rs) uses it for every command: the one unprivileged GUEST_ID and a per-exec cgroup, the envelope’s seccomp deny-set, and close-on-exec marking above stderr. The daemon disables the user namespaces bwrap needs. GrantStack::net, the stack’s one veto, carries any layer’s to both the host projection and JailPlan: an offline guest command gets a fresh network namespace with loopback up. IP egress and outside abstract Unix sockets are out of reach; the guest jail installs no Landlock domain, so pathname socket reachability is determined by its shared filesystem. The in-process guards apply unchanged (docs/SPEC.md §12.11): fs and exec bind the command head, and the guest builds no filesystem or executable projection to constrain an admitted program’s descendants (rg --pre, env, find -exec). Their filesystem and execution boundary is the jail and the VM wall. The seccomp deny-set and offline namespace bind descendants.

  • pin() and boot() — startup: pin pins ral’s own executable (reexec::OWN) and, on Linux, the bwrap envelope (linux::pin_envelope, walked on the process’s own PATH before any shell exists); boot is pin and, on Windows, the boot-time orphan sweep (windows::session::boot_recover) that deletes a crashed prior session’s AppContainer profiles, matching their ledger owner by PID, image and creation time. A test binary is the same multicall executable a confined child re-execs, so it must serve these flags from its own pre-main #[ctor] (it reaches main only through libtest). invocation::serve(&role, installers) (core/src/invocation.rs) is the one pre-main dispatch, over the role core/src/role.rs’s classify named — run by ral, exarch and every test #[ctor] alike, surfacing a served role’s exit code so the caller can terminate. It serves a Warrant role first (serve_warrant), before any pin, so the trampoline pins and opens nothing before it is confined; the pipeline anchor spawns nothing and runs unpinned. Every other role — the engine, the shell — runs boot first, and the BundledTool multicall only pins, so an --engine process has bwrap pinned exactly as the shell does. Skip it and OWN stays unpinned, so the per-command launcher refuses to re-exec a binary it cannot vouch for.
  • test_helper::confinement shares live enforcement evidence across core, ral and exarch tests. require_confinement! obtains a cached Confining only after an fs-confined /bin/echo exits successfully with its exact marker (cmd /c echo on Windows), under a read-only grant on a fresh temporary working directory. An unavailable envelope or an already-profiled Seatbelt runner prints the test’s skip reason locally; RAL_REQUIRE_SANDBOX makes that a failure. CI requires it in Linux containers and native CI runs. admitted checks a successful control and its marker; denied takes that control under the same grant and checks the denied operation cannot return the marker. A masked file can read as empty with exit zero, so status alone cannot establish denial. Coverage includes top-level dispatch, grant, spawn, par, pipeline stages and out-of-grant reads on both Unix backends. Test constructors also serve RAL_TEST_PROBE, a JSON argument array for descriptor, socket, resolver and platform IPC probes. Warrants and anchors take precedence; an ordinary probe runs before boot opens any descriptors. A Landlock ABI test (landlock_reaches) fails under the requirement where Landlock is absent, below ral’s own minimum (BASELINE_ABI, ABI 1: plan refuses an exec-restricting grant without it); a kernel at or above it but below the test’s ABI skips through skip_beyond_baseline, never a failure. Volume prerequisites name their skip reason independently of the confinement requirement. core/tests/local_ipc.rs covers live host socket refusals, online IP controls (UDP requires the host peer’s echo), macOS resolver and shared-memory access, and Linux abstract peers inside one launch (Landlock ABI 6). Windows session tests inspect the staged launch’s network SIDs across offline/online transitions; AppContainer loopback cannot supply a live peer control. core/tests/sandbox_assurance.rs checks rename targets, directory removal, and a detached child’s read released by pipe only after its host exits. The macOS warrant test approaches the socket-buffer ceiling: the complete warrant arrives, or preparation refuses before spawning.
  • reexec.rs — Pinned, an executable pinned at boot: the one shape every Command the sandbox execs is built from, so nothing a session does to its environment can choose the file. Two are pinned: this executable (OWN), so a confined re-exec runs the same binary even under an on-disk swap, and on Linux the bwrap envelope (linux::ENVELOPE). Its methods are arg0 (the on-disk path, argv[0] of every exec), command (the Command that execs the pin: through /proc/self/fd/<N> on Linux, by name elsewhere), object_id, on Linux fd (the pinned descriptor) and names (the inode’s current name, None once unlinked), and on macOS verify; reexec::launch(role) is the one launch entry for the unconfined re-execs (the pipeline anchor, a bundled tool), through the pin when there is one, and reexec::own() is ral’s own pin as a Result, so a sandboxed launch refuses when ral could not pin itself. A swap is askable where the host can say so: on Linux the retained descriptor makes /proc/self/fd/N resolve to the boot inode; on macOS verify re-walks the name and compares its ObjectId before each spawn; on Windows nothing is pinned, since there is no parent-side self re-exec for a guard to protect and launch takes the live current_exe. On Windows there is no child re-entry at all — confinement is the AppContainer token the parent attaches at CreateProcessW, so a child asking to confine itself (--warrant) is refused with 126, and the pinned self serves to grant the container read on the bundled-tool re-exec image. Pinned::verify, the parent-side swap guard, is macOS’s alone, which execs the trampoline by name; Linux execs it from ral’s pin, lent like every descriptor, so there is no name to verify.
  • projection.rs — the sandbox’s own view of authority: SandboxProjection::of(&GrantStack, &Baseline, Option<&Admitted>) meet-folds the stack once, at spawn, into FsProjection (read: Vec<FsAllow>, the live positives of the read region with run places and live support among them, beside the write prefixes, the system reads and the exclusions; allowances keep their resolved positions up to rendering, exclusions stay the read table’s FsDenys and render from the resolved real paths their walks held; deny comes from the read region alone, the two regions holding the same exclusions, so a disk change between the two folds can only drop a write allow, which fails closed; FsLists, whose SandboxProjection::rendered derives pinned_dirs and whose read_withheld gives the read table’s verdict; no write reach classification) and ExecProjection::Restricted(KernelRules), the stack’s table compiled once here, for_kernel, joined with the live support (sandbox::carriers); Admitted brings only the launched file whose carriers are support. It takes no Shell; Shell::sandbox_projection (shell/runtime/state/checks.rs) is the entry.
  • WITHHOLDS_GPU (sandbox.rs) — read by SandboxProjection::of and by protocol::probe::Grants::of into withholds_gpu: the one place the host’s inability to withhold the GPU (Windows) is stated. A withheld GPU there projects as left on and refuses nothing.
  • sandbox::unavailable (defined in process/launch.rs, re-exported by sandbox.rs) — mints the Error for a confinement this host cannot establish, so that nothing ran and it is never the command’s fault: there was no bwrap on PATH to pin at boot (linux::envelope, asked at the first launch that needs it), or the pinned envelope failed to spawn.
  • Launch::new (process/launch.rs) builds the unsandboxed external exec image; Command::prepare reaches it directly when no projection is active.
  • launch.rs (Confinement::launch, ProgramLaunch, sandboxed_command) — the per-command launcher. ProgramLaunch is Direct(Launch) or, on Linux, Enveloped(EnvelopedLaunch); launch_mut configures either inner launch, and spawn and spawn_detached dispatch once. Confinement::denial_pids names the pids whose kernel denials a spawned child owns. Unconfined and guest-jail launches are always direct. macOS builds a direct Launch::trampolined with its report fixed at construction; Windows keeps its direct launch and token description. Linux bwrapped and enveloped return the envelope’s own launch type, with mandatory report and diagnostics. Command::prepare (shell/exec/command.rs) routes an external or bundled child through here whenever a projection is active and the process is not already confined, confining that one child, the Admitted’s program: a Program::File by the real path the guard judged, its spelling as argv[0], or a Program::Tool. macOS and Linux share one trampoline: the pinned ral itself, whose whole argv is ral --warrant <w> <r> (Role::Warrant), the warrant’s descriptor and the report socket’s. The confinement to enter and the program to run cross in a Warrant (sandbox/warrant.rs, its fields private) compiled in the parent. The confinement is Confinement, one type per platform with spell, parse and enter: on macOS the profile macos::build_profile compiled, and on Linux an Option<Landlocked>, spelled unconfined, landlock@<fd> or landlock+refer@<fd>, the ruleset’s descriptor; the program is an Image: a file carries its real path and argv[0], a tool a &'static str from the bundled-tool table. Head resolution and warrant decoding use the same lookup; unknown tools and nonabsolute files refuse. Warrant::confine is the only way to the program: receive and verify the warrant, enter the confinement (macos::apply_profile, Landlocked::enter), sweep every descriptor above stderr but the report’s, and yield a Confined, whose run says on the report what became of the program. macOS execves a host file in place and runs a bundled tool here (uutils::serve); Linux supervises, spawning the file or forking the tool and reporting the exact wait status (a-supervisor-never-execs, the-trampoline-is-a-supervisor). serve_warrant serves the child and exits with a verdict only where a report cannot carry one: a failure to enter the confinement is a refused record, a program that cannot start an unstarted(errno) (a-launchs-report-is-the-trampolines-alone). The encoding is NUL-terminated fields behind a ral-warrant/5 magic: a file is its real path, then its argv[0] spelling, then its argc and argv (the interpreter, read by the parent, stays the parent’s); a tool its name, then its argc and argv; canonical (decode re-encodes and compares) and at most 8 MiB. It rides a descriptor, only its number in argv: a sealed memfd on Linux, checked again after sealing, and on macOS a prefilled socketpair whose writer closes before the child exists; the child refuses an unsealed memfd or a non-socket. Every descriptor a launch hands down crosses at the number a Handoff (warrant/handoff.rs) lifted it to, from 98 up (Slot): bwrap’s --args, the warrant, --info-fd (a socketpair, which unlike a pipe cannot be reopened through /proc) and the payload’s copy of its writer, whose sweep ends the parent’s read once the payload’s group exists, the Landlock ruleset, ral’s pin, the trampoline bwrap execs, the seccomp programs (sealed memfds) and one mount handle per bind. The handoff’s one pre_exec only clears close-on-exec: nothing is dup2’d, so no descriptor it still uses (std’s exec-error pipe, detach’s handshake) can be displaced. Each number is named as data: to bwrap in its options, the ruleset’s in the warrant’s confinement, the warrant’s in the trampoline’s argv. The Linux child sweeps everything above stderr with close_range after Landlocked::enter consumes the ruleset. macOS lists descriptors with proc_pidinfo(PROC_PIDLISTFDS) and closes each above stderr before Seatbelt entry, including those above a lowered soft limit. The warrant role opens nothing before the sweep; a Confined promises both confinement and stdio alone. macOS spawns the trampoline directly; Linux spawns it under bwrap (bwrap_command), giving the full shape bwrap → ral trampoline → Landlock → the program, its child. The real argv is bwrap --args <a> -- /proc/self/fd/<t> --warrant <w>: bwrap_argv is pure in descriptor numbers and returns bwrap’s options alone, which bwrap takes from --args. The order is forced rather than chosen: a Landlock domain handling any fs right forbids mount(2), bwrap’s first act, so the layer can only be entered inside the envelope bwrap has already built. Linux’s confinement names no path: the parent opens every admit by handle, never through a symlink, so each rule reaches the file a grant froze. landlock::build plans the handled set from the parent’s one probe (plan), creates the Ruleset by raw syscall, and admits each allowed file as itself and each live allowed directory as its hierarchy less what the table blocks beneath it (expand, which stops where a bind mount loops back onto a directory it is listing), each opened in the host by open_nofollow / open_dir_nofollow (RealPath’s walk with every link refused, held as Installing); an absent admit is dropped, a file admit whose path has since become a directory is dropped, not admitted as a hierarchy, a symlink since planted refuses the launch, and a restricting exec projection is refused where Landlock is unavailable. The payload probes nothing: it takes the ruleset at its slot, adds only Refer on its own root, which exists nowhere else, and fails closed if a promised ruleset never arrived. bwrap_command takes the Envelope (bwrap’s pin, the trampoline’s, and the HostEnvelope probed once by running that trampoline as a pipeline anchor), the image (Program::File’s real path, the file the trampoline execs), the handoff so far and the rendered projection, and refuses outright under a bwrap that builds no envelope, in bwrap’s own words, or one without --ro-bind-fd (HostEnvelope::builds). Binds::open is the one place a launch opens what it mounts: the read-only defaults, the read and write prefixes, the image, each allowed file and live allowed directory of the ExecRules of the ExecProjection, and the cgroup tree in the Over layer, each object (render_objects: a path’s canonical spelling, its other spellings mounted too unless within another bind) opened once by open_nofollow and lent once per bind. A read-only bind within another bind is dropped, a writable one only within a writable one; an absent object drops its binds, and so does a system default this user may not reach, while a name now reaching outside what was rendered refuses the launch. Every allowance is bound as its resolved real position, a redirected one refusing the launch, and each deny mask goes on wherever the final bind layers show the denied path (Binds::names): names beneath an Over destination are replaced by what that bind shows, so cgroup exclusions follow the re-rooted tree. A mount laid inside one bind of an object does not show at another, so a prefix written through a symlink, two binds of one handle, is masked at both. A deny hiding /proc is refused, the envelope starting its trampoline through it, and so is one holding the working directory, which no --chdir can enter. The two pins join the Over layer by copies of their own descriptors, read-only at the names their inodes hold now (pinned, over Pinned::names), an unlinked pin binding nothing. bwrap_argv emits --ro-bind-fd/--bind-fd from the same vector, Shown, before /proc and /dev, Over after. --chdir carries the context’s absolute CwdPath bytes, while every rendered name refuses a position that is not Unicode rather than go lossy into bwrap’s argv. A malformed or unreadable InfoFd record makes EnvelopedLaunch::spawn kill and reap the envelope before returning its error; an empty record means bwrap died before reporting its payload. Windows builds the target’s Launch directly with a Confined describing its token, and every Launch::spawn runs windows::session::confine, which stamps and returns its projection’s AppContainer LowBox SECURITY_CAPABILITIES for CreateProcessW, so the parent’s own spawn is the confinement point — never a re-exec child. The process module’s spawn_lock::lock_inheritance serializes raw Launch creation and temporary inherit-flag restoration with helper-backed Command::spawn, releasing before Job Object placement/resume and waits. The raw child’s explicit handle list restricts only that child; unrelated dependency spawns remain outside ral’s mutex and may still inherit temporarily exposed handles. A bundled tool there is a plain ral --ral-bundled-tool <tool> carrying no warrant, and serve_warrant refuses --warrant outright. The launcher also takes an Ownership (Kept / Surrendered, the second variant cfg(unix) since only there does the verb that makes the distinction exist): it reaches the Linux backend alone, which decides the two ties between the session and the envelope — death (--die-with-parent) and address (--info-fd) — so a detached survivor keeps the birthing frame’s projection, namespaces included, for life while dropping both (runtime). The grant body itself evaluates locally, external children being confined per-command (sandbox-external-children).
  • Backends: macos.rs (Seatbelt, macos-base.sbpl; Profile, a record whose field order is the rule precedence (no freeze section), and in every profile ral’s own file is write-denied and its ancestors unlink-denied), process/limits/fork_brake.rs (macOS’s process budget: the confined child’s RLIMIT_NPROC, the user’s count at launch plus 512, bounded by the system ceiling and inherited hard limit; failed setrlimit refuses the launch, and limits::failure_hint explains a possible fork refusal on status 128 without asserting its cause), linux.rs (bwrap: the Pinned envelope, exec’d by descriptor and never by name, its own file read-only bound inside every envelope after the projection’s binds; the argv — --new-session, the ipc/uts/cgroup namespaces and, by host fact, the pid one, --proc on both projections, the seccomp deny-set (sandbox/linux/seccomp.rs: Filter, Syscall, explain; process reach includes pidfd_getfd, process_madvise, process_mrelease and kcmp, with modify_ldt also killed on x86-64; kill, pidfd_open and pidfd_send_signal remain admitted; ioctl refuses TIOCSTI and TIOCLINUX; socket admits only Unix, IPv4, IPv6 and routing netlink, socketpair only Unix, and io_uring is refused with EPERM; When holds alternatives of conjunctions, checked at compile time; Programs retains compiled BPF and installs it without allocating or locking; linux.rs::seccomp_programs serialises per launch); InfoFd, the payload’s pid read back for a Kept launch; linux/host.rs, HostEnvelope, the probed host facts the render is pure in; linux/gpu.rs, GpuNodes, the GPU’s device nodes and sysfs found at each launch and bound by name), and windows.rs (Job Objects capping the child tree at 512 processes, plus the AppContainer backend in windows/: appcontainer.rs owns profiles and LowBox SECURITY_CAPABILITIES; dacl/mod.rs exposes the path-derived capability-SID engine; session.rs composes them). Within dacl/, stamp.rs owns completion witnesses, mutex.rs per-path locks (named by the path’s Windows collision key, folded beyond ASCII and at least as far as NTFS folds, where the witness and capability name are not: a lock errs toward merging, a witness toward splitting, and the stamp store is locked by an environment-spelled path two sessions may spell apart), ledger.rs profile recovery, and acl.rs queried descriptors and borrowed ACEs. Both files keep their JSON in one held OwnDir, $XDG_STATE_HOME/ral/sandbox-dacl/ (ledger_dir), each replaced whole by OwnDir::store. windows/local.rs owns Win32 local allocations. Kernel handles use OwnedHandle; the path mutex guard stays on its acquiring thread. Ported units retain their MXC provenance.

The Windows backend is path-keyed: each (canonical path, kind) grant — kind ∈ {rw, ro, ls} — derives a deterministic capability name ral.fs.<kind>.<128-bit-truncated SHA-256 of the canonical path> — hashed as-is, never case-folded, so a case-sensitive directory’s two distinct names cannot merge into one authority — and thence a capability SID via DeriveCapabilitySidsFromName (dacl::fs_capability_name). dacl::ensure_frozen_grant stamps that SID’s inheritable ACE once and never reverts it. A read-write grant is two permanent mutations, and neither witnesses the other: the mandatory-integrity check runs before the AppContainer pass, and an unlabeled object defaults to Medium, refusing every Low-IL child whatever the DACL says — so ensure_low_integrity_label also stamps a Low SYSTEM_MANDATORY_LABEL_ACE, asked before anything about the ACE, even where the well-known AppContainer SIDs make the ACE itself redundant, and witnessed under its own stamp key and its own SACL probe. For each mutation two witnesses gate skipping it — the completion store (stamps.json in that directory, replaced whole and atomically by OwnDir::store, per-path named-mutex merge) recording completed propagations, and a probe of the root’s own DACL confirming its ACE remains. Before an ACE is reapplied, its old completion witness is removed under the path mutex; recording follows the apply, so a crash mid-propagation leaves no witness and the next grant re-stamps idempotently while a child in the interim fails closed. A spawn’s kernel-checked reach is then exactly the capability SIDs session::confine mints into its token, those of its own launch’s grants and no other’s, so attenuation shrinks-only: a narrowed grant or subagent gets a token lacking the wider paths’ capabilities. An ACE lives on the NTFS object and Windows does not re-inherit on a same-volume rename, so stamped authority is object-sticky where a grant rule is path-based — dacl/mod.rs’s module header records the resulting drift in both directions (path-derived-capability-sids). Every frozen allowance is checked before the session’s memo and stamped through a held handle on the very object checked, no redirecting reparse point on its path (a redirected one refuses the launch; a name surrogate redirects, a cloud placeholder does not; confined-launch), and a position that is not Unicode refused as DaclError::NotUnicode, since a Windows grant names its object by text; and a launch whose fs projection holds the universal prefix is refused before anything is stamped. Within that shape: an AppContainer profile is still minted per distinct fs projection (SessionSandbox maps ProjectionKey to profile) for the deny-by-default token and named-object namespace separation, carrying no fs authority, and DaclManager is the profile ledger — teardown deletes profiles but restores no ACEs. The session caches Arc<OwnedContainerSid>, Arc<OwnedCapabilitySid> and Arc<CapabilitySids>; each staged Launch retains those owners independently of teardown. The spawn builds its raw SID array locally and holds it through CreateProcessW, so deleting a profile registration cannot free a launch’s SID allocations. A deny stamps nothing: the AppContainer pass of the access check matches a deny ACE against the token’s ordinary groups only, never its capability SIDs, so Windows cannot take back what a grant’s ACE admits (path-derived-capability-sids, amendment of 2026-10-20). So session::confine first carves each exclusion out of the allowances around it: sandbox::carve::carve, a pure planner over an injected lister and tested on every host, replaces such an allowance with its existing entries less the excluded ones, down to each exclusion, and grants each directory on the way only its own listing (GrantKind::List, an ACE nothing inherits), so a name made there later, the excluded one included, reaches nothing granted; links among the entries are neither granted nor followed. An exclusion on or around an allowance, the program image included, cannot be carved, and session::refuse_deny_meeting_grant refuses it before anything is stamped. For every exclusion dacl/deny.rs’s ensure_unreachable then runs AuthzAccessCheck at each launch, in an AuthZ context carrying the child’s package and capability SIDs, on every object beneath it, refusing the launch if any right is granted — an ALL APPLICATION PACKAGES ACE, or a hard link carrying a granted file’s ACE. The walk checks reparse points as themselves without following them, polls cancel per entry, and refuses an exclusion it cannot read. The child’s program image is granted read-only, to its own launch, so a user-installed binary or the bundled-tool self image can load at all, handed to session::confine as a RealPath, so the canonical form the pin and the stamp’s local-prefix allow-list demand is the type’s, not the caller’s care; and net: `offline is enforced by withholding the network capability SIDs — a LowBox token without them cannot open a socket, so the network axis is enforced on Windows.

macos-base.sbpl is the policy-independent Seatbelt base every rendered macOS profile inherits, and build_profile lays the grant’s rules over it. Its POSIX shared-memory allowance reads only apple.shm.notification_center and com.apple.featureflags.shm, with no write allowance. Both are read rule by rule — what each admits, what it withholds and why, and what the backend pays to express an object policy in Seatbelt’s name language — in seatbelt-profile.

Path-scoped exec confinement on Linux is a Landlock layer the payload enters inside the envelope; a deny inside an allowed directory is subtracted over the tree at launch, and only a veto under a trusted admit stays with the in-process guard — landlock-exec-layer.

diag.rs (with per-platform readers in diag/macos.rs / diag/linux.rs) turns a kernel-reported sandbox denial into an actionable hint on the failing command’s Error: it reads the kernel log over the call’s wall window (Seatbelt on macOS, the seccomp record inside bwrap on Linux), and retains only parsed Records whose pid the call’s start claimed (an-external-end-to-end). The heading says “sandbox denials were recorded for this command’s processes:”; a denial beside a failure does not establish its cause. The parsed operation decides the remedy, and the hint answers once per class present: a file-read* path is offered to the grant’s read set and a file-write* one to write (advice that fails twice, otherwise), a process-exec path to the exec set — the layer a re-exec through sh -c or find -exec reaches, and the only one that sees it — a network-* denial to the net axis alone, a Metal device, IOSurface or compiler denial to the gpu axis alone, and a mach-*/ipc-* operand to nothing at all, because a service is the base profile’s to decide and no grant widens one. Denied is that taxonomy as a type, and every operand it holds is an Inert: C0, C1 and DEL become visible escapes, at most 512 Unicode scalar values are taken, and truncation is marked. Raw log lines never enter the rendered hint. A service name cannot arrive where a path is expected; withheld services carrying a reason (macos.rs::withheld_service, the .sbpl’s prose as data) are quoted with it and lead the hint, since they are the one class the reader cannot act on — the securityd denial that broke cargo fetch was once ranked below a .GlobalPreferences.plist probe and answered with a grant that would have changed nothing. macOS logs fully-resolved paths, so the hint names the exact path with the symlink caveat; on Linux, an operandless denial first tries describe_denial, which consults the seccomp deny-set by syscall number and the parsed code= action. It repeats a rule’s reason only when both match, including the errno value; another action earns no ral explanation. A foreign-ABI record (an arch= mismatch) receives the arch prologue’s explanation only for KILL_PROCESS; only where the deny-set has nothing to say does the hint fall back, and it then says the record names no operand rather than guessing at a set to widen. Windows has no kernel denial log to scrape at all, so its arm gates on the exit code alone: only an access-denied-shaped exit (ERROR_ACCESS_DENIED / STATUS_ACCESS_DENIED) under an active sandbox yields the fixed, pathless hint: never a fabricated path.

A script refused at its start reads no log: interpreter_hint asks the launch’s own projection what withholds its #! interpreter, the kernel exec table and then the read table (FsLists::read_withheld), and names an exclusion first (no allowance reopens one), then a missing exec allowance, then a missing read, each with the grant entry that admits it. The last is the case bwrap shows as an absent interpreter.

collect(Collector) runs fixed absolute system paths: /usr/bin/log show --style ndjson on macOS; /usr/bin/journalctl or /bin/journalctl with -k -o json on Linux, falling back to /usr/bin/dmesg or /bin/dmesg. Each collector has a 2-second deadline and a 1 MiB stdout ceiling, and is reaped on every outcome. A bound or failure supplies no hint, leaving the command’s own error. JSON is decoded before eventMessage or MESSAGE is parsed, so an operand’s newline cannot start another record. The macOS message must begin with Sandbox: and its first (<digits>) deny(<digits>) supplies the PID, followed by the operation and inert operand.

This boundary is what exarch reuses as its sandbox. Bundled tools route through the exec chokepoint in-process; their filesystem access has no in-process guard, so a bundled tool is never inlined — it is spawned as a ral --ral-bundled-tool child and, under a restrictive grant, floored by the OS profile of the per-command sandbox it runs in (bundled-tools-as-exec-images, bundled-tools-always-reexec). That single binary carrying both ral and its coreutils is part of why ral is a single-binary. docs/SPEC.md gives the formal capability calculus.

Every fs/process constructor in this layer is a typed site: the workspace bans the raw constructors via clippy disallowed_methods, so each call is wrapped in site! with a variant that names it, a Surface one for the exec image that raises a card (Launch::new, Surface::ProcessLaunch) and a Silent one for infrastructure (the self re-exec, the pinned binaries’ exec (Pinned::command), the ps denial sampler, the boot-time binary pin). Raw libc::{syscall, socket, connect, bind, fork} and rustix::fs::stat are banned too: each Landlock operation, the inherited-fd sweep and both core forks have distinct Silent sites. Guest crates retain their crate-root exemptions; test code carries one blanket per module. The enums are the list: core/src/site.rs for cross-domain sites, and domain-local site.rs declarations in path, host, own, process and sync, each variant documenting why its place is exempt. Ungoverned::{read, region, write} are also clippy-banned, so each authority mint is a documented typed site. core/src/own/site.rs declares the two own-file authority mints (Silent::{Read, Write}, the second over a file or a directory), used in own.rs, but no syscall sites, since every syscall it needs is a walk primitive (own-files). The site shapes and their rail rendering live in io-surface; here the sites are only declared and accounted, with clippy failing CI on a constructor under no site and on a site that no longer wraps one, and core/tests/sites.rs on any other exemption, on a lint group that silences the lint, and on a member outside the workspace’s lints (typed-sites).