Cross-platform execution capsules
Execution capsules give Tirith-launched programs a per-run OS boundary. A caller describes the needed file roots, network mode, environment, handles, and resource limits in one capsule specification. Tirith selects the host backend, checks the coverage it can really provide, and either launches the child with that coverage or refuses before uncontained execution. This page expands the capsule part of execution isolation and provenance and relates to execution provenance and trust.
Capsule launch model
The capsule layer separates a portable launch plan from the platform action that applies it. CapsuleSpec expresses intent. CapsuleCoverage records the controls that are active. The CLI launch seam turns this pair into either a completed result or a managed live child.
The common launch contract covers these concerns:
| Concern | Capsule behavior |
|---|---|
| Filesystem | Read and write access uses explicit roots over a deny-by-default set of sensitive paths. |
| Network | DenyAll is the normal mode. Domain allow-lists require a verified broker path as well as raw-socket denial. |
| Environment | Sensitive credentials are removed. A temporary home and temporary data paths can replace the real user profile. |
| Handles | Unix file descriptors or Windows handles are reduced to the stated set. |
| Resources | CPU, memory, process, open-file, output, and wall-time limits are treated as one coverage claim. Every requested dimension must be supported. |
| Reporting | The result names the backend and achieved coverage. A degraded result is explicit rather than implied. |
The main CLI seam is home/…/capsule.rs. select_backend probes the host before launch. run_to_completion_os runs a child with inherited standard I/O. spawn_piped returns a managed child for a caller that must bridge standard I/O. run_to_completion_bound_inputs provides the stricter content-bound shape used by package installation.
Platform backends
Each supported platform maps the same capsule intent to a native process boundary. The differences are in how the OS grants file access, blocks network use, limits the child tree, and starts the target.
| Platform | Backend | Boundary shape | Main product limit |
|---|---|---|---|
| Linux | landlock-seccomp | A trusted re-exec launcher applies filesystem, syscall, environment, and handle controls before it starts the target. | Full target-execution proof and capability-bound package execution depend on the supported Linux architecture and kernel facilities. |
| macOS | seatbelt | A trusted re-exec launcher prepares a Seatbelt profile, closes extra descriptors, applies supported limits, and execs sandbox-exec. | Domain egress still needs the broker. macOS cannot honestly provide per-child process, memory, output, or wall-time limits through this path. |
| Windows | appcontainer | A per-launch AppContainer receives ACL grants. A suspended child is assigned to a kill-on-close Job Object before it resumes. The CLI wait path enforces the wall-clock deadline. | Piped standard-I/O containment is not wired into the Windows launch shape. Open-file and output limits are not supported by the Job Object plan. |
| Other targets | noop | No OS containment is applied. | Enforcing callers refuse. Only an explicitly best-effort analysis caller may run degraded. |
Linux capsule
The Linux capsule uses Landlock for filesystem confinement and seccomp for syscall control. The __capsule-child launcher runs as a real single-threaded process so it can apply the boundary safely. It closes unexpected descriptors before it lowers the file limit, sets resource limits and no-new-privileges, applies the filesystem and syscall rules, scrubs the environment, and then starts the target. The target inherits the Landlock and seccomp state across exec.
For live execution, the launcher remains as the stable process-group guard. It supervises the target tree and owns wall-time and combined output limits that the Linux OS backend does not provide as coverage. The parent can kill and reap the full group instead of treating the direct child as the whole execution.
Linux also supports capability-bound launches. The package path passes sealed input files and held directory capabilities to the launcher. The launcher exposes only the named inputs and binds writes to the held target directory. The project-run path uses the same held-directory idea for a temporary writable project copy. This keeps a later path rename or replacement from changing what the child can read or write.
References: crates/…/linux.rs• L1-57 crates/…/linux.rs• L284-301 crates/…/capsule_child.rs• L1289-1361 crates/…/capsule.rs• L2318-2351 crates/…/capsule_run.rs• L477-631
macOS capsule
The macOS capsule represents the boundary as a Seatbelt profile. The profile starts with deny-by-default rules, adds the validated read and write roots, and denies network access. A domain allow-list can open only the loopback path to the egress broker; the broker remains responsible for the domain and destination checks.
The CLI first re-execs the trusted __capsule-child launcher. That process closes unrelated descriptors and applies CPU and open-file limits before it execs the absolute /usr/bin/sandbox-exec path with the target. The environment is rebuilt from allowed variables and can point HOME, temporary files, and XDG paths at a fresh directory.
Seatbelt does not provide a trustworthy per-child process-count, memory, output, or wall-time limit in this capsule contract. If a caller requests any unsupported resource dimension, the aggregate resource coverage is incomplete and an enforcing caller refuses the launch.
References: crates/…/macos.rs• L1-59 crates/…/macos.rs• L157-237 crates/…/capsule_child.rs• L1204-1267 crates/…/capsule.rs• L6233-6303
Windows capsule
The Windows capsule creates a unique AppContainer identity for each launch. The executor grants that identity access to the exact filesystem roots through ACL entries. It grants no networking capability for the deny-all mode. The grants are tracked so Tirith can remove only the entries created for that run.
The child is created suspended with the AppContainer security attribute and a scrubbed environment. Tirith creates and configures a Job Object, assigns the child, and only then resumes its primary thread. The Job Object kills the child tree when the job closes and can enforce CPU, memory, and process-count limits. The CLI wait path enforces a wall-clock limit. A failed step terminates the suspended or running child and revokes partial grants instead of returning an uncontained process.
References: crates/…/windows.rs• L1-71 crates/…/windows.rs• L162-214 crates/…/windows.rs• L436-583 crates/…/capsule.rs• L5181-5192
CLI execution surfaces
The CLI exposes different launch shapes because a command, a protocol server, a package installer, and an untrusted project have different ownership needs. All shapes pass through backend selection and the coverage gate.
Completed child runs
tirith run uses the capsule for every live script execution. The legacy --capsule spelling remains accepted, but it does not turn containment into an optional boundary. The command passes the typed interpreter invocation and reviewed script to run_to_completion_os. The command refuses when the selected backend cannot meet the required coverage.
References: crates/…/run.rs• L157-239 crates/…/capsule.rs• L5147-5229
tirith temp-run --capsule uses the same completed-run seam with a temporary directory as the main read and write area. This surface is a best-effort impact preview, not an enforcing security boundary. A host without usable coverage may therefore run the command uncontained, but the result prints a degraded banner.
References: crates/…/temp_run.rs• L400-484
Untrusted project runs
tirith capsule run --preset untrusted-project runs a supplied project from a private copy instead of from the operator's working tree. The preset denies network access, strips the inherited environment, uses a fixed command path, denies known credential stores, and gives the child write access only to the copy. It is an enforcing surface with no degraded mode.
The command checks the task gate and backend coverage before it copies or starts the project. It records the input tree, output tree, file diff, child result, coverage, and cleanup state in a receipt. The preset is currently enforceable only on x86_64 Linux with usable Landlock support because its resource and raw-network controls need both the Linux launcher and its parent supervisor.
References: crates/…/capsule_run.rs• L1-70 crates/…/capsule_run.rs• L217-401 crates/…/capsule_run.rs• L462-721 crates/…/mod.rs• L813-855
Piped child proxies
The gateway uses spawn_piped because it must keep a live child and bridge the child's standard input and output to the MCP client. The gateway's capsule policy denies network access, permits the runtime files and current working directory it needs, keeps only a small environment, and preserves its recursion-depth marker. The gateway uses fail-closed policy, so a degraded backend never starts an uncontained upstream server.
The managed child owns its temporary home and process-tree lifetime. The caller must consume the exposed pipes and finish the child through its lifecycle methods. On Linux, the supervisor also enforces the combined output and wall-time budget while the bridge is active. Windows does not provide this contained piped shape, so an enforcing caller refuses before starting the upstream process.
References: crates/…/gateway.rs• L1523-1554 crates/…/capsule.rs• L5294-5354 crates/…/capsule.rs• L6572-6589
Content-bound package execution
The package installer uses run_to_completion_bound_inputs rather than a path-only command launch. Before the child starts, the installer binds the exact interpreter, seals and hashes the approved requirements file and wheels, and holds the destination directory capability. Linux exposes those inputs by safe names inside a private view and allows writes only to the held target.
This launch shape is enforcing and is available only on x86_64 Linux. Other platforms and unsupported Linux architectures refuse before the package interpreter starts. A clean child exit then permits the package flow to perform its separate post-install integrity check.
References: crates/…/pkg_install.rs• L1349-1512 crates/…/capsule.rs• L2318-2351
Launch and child lifecycle
The normal Unix path uses a hidden internal command. The parent serializes the capsule specification and starts tirith __capsule-child; the hidden launcher applies the platform boundary and then starts the requested program. Windows applies its native plan directly because its process creation API needs an AppContainer attribute list.
The following diagram shows how the shared CLI seam reaches the platform-specific boundary and returns either a managed result or a refusal.
flowchart TD
A[CLI surface] --> B[CapsuleSpec]
B --> C[Select backend and compare coverage]
C -->|Shortfall on enforcing surface| D[Refuse before uncontained run]
C -->|Linux| E[Re-exec __capsule-child]
C -->|macOS| F[Re-exec __capsule-child]
C -->|Windows| G[Apply AppContainer launch plan]
E --> H[Landlock and seccomp, then target]
F --> I[Seatbelt profile, then target]
G --> J[ACLs and Job Object, then target]
H --> K[Managed child or exit result]
I --> K
J --> K
Linux reviewed execution adds a parent-child authorization step. The guard reports that the target reached the kernel exec stop while the target remains stopped. The parent records the transition, sends the exact authorization frame, and accepts the resumed state only after the guard confirms it. Bad frames, missing EOF, expired deadlines, or guard failures terminate and reap the supervised tree without upgrading the event to confirmed execution.
The same launcher reports achieved coverage after it applies the boundary. The parent does not turn a pre-launch probe into an execution claim. It accepts the run only after the achieved coverage report and any required target-exec evidence arrive through their separate channels.
Internal launcher interface
home/…/capsule_child.rs owns the hidden __capsule-child interface. Its arguments carry the serialized spec, target program, optional sealed descriptors, temporary-home capability, bound working-directory capability, content-bound input capabilities, and launch-status channels. The parser rejects missing pairs, duplicate descriptors, unsafe input names, and incomplete bound-input sets.
The parent can bind either a read-only working directory or a writable work directory to a retained descriptor. The latter is used by the untrusted-project preset. In both cases the pathname is evidence that is checked against the held directory identity; the descriptor supplies the authority.
home/…/main.rs checks for this invocation before it starts Tirith's normal worker thread. This ordering preserves the Linux single-threaded requirement and ensures launcher setup failures exit rather than fall through to ordinary execution.
References: crates/…/capsule_child.rs• L49-61 crates/…/capsule_child.rs• L133-471 crates/…/capsule_child.rs• L1289-1361 crates/…/capsule_child.rs• L1583-1659 crates/…/main.rs• L7098-7125
Coverage and failure policy
Coverage is a statement about controls already in place, not a promise inferred from the requested spec. A backend that lacks a host feature reports the matching field as false. NoOpCapsule reports no coverage at all.
The selected coverage is compared with the spec's required coverage before a security boundary is crossed. Enforcing surfaces use FailClosed. The only intentional degraded path is temp-run --capsule, which uses AllowDegraded and reports that it ran uncontained.
The egress broker does not replace the OS boundary. An allow-listed domain mode is safe only when the backend blocks raw outbound sockets and the broker authenticates the session, checks the domain and port, validates resolved addresses, pins the destination, and applies tunnel limits. The current capsule backends do not claim end-to-end domain-proxy coverage, so enforcing allow-listed launches fail closed.
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the coverage ledger, backend probes, child-side achieved-coverage report, and parent result aligned. A new control must not be marked enforced before the OS action and its failure path exist.
- Keep
run_to_completion_os,spawn_piped, bound-input launches, and the untrusted-project launch aligned with the backend's degraded policy. A new enforcing caller must use fail-closed behavior. - Keep the hidden launcher argument pairs and descriptor allow-list aligned with the parent command builder. A new capability must be passed, retained, closed, and validated as one contract.
- Keep Windows plan creation and Win32 plan application in step. Any new ACL, AppContainer, or Job Object grant needs cleanup on both normal completion and partial failure.
- Keep resource coverage all-or-nothing for each requested spec. Adding a limit to one platform can change which CLI surfaces are allowed to run there.
- Keep the gateway's piped-child support separate from Windows' non-piped launch support. Do not treat a successful Windows completed run as proof that a Windows protocol proxy is contained.
- Keep the untrusted-project preset's copy identity, task-gate ceiling, receipt state, and cleanup proof aligned. A writable pathname must not replace the retained project-copy capability.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Required coverage is missing or a backend probe fails | An enforcing surface refuses before the target runs. | Compare SelectedBackend coverage with CapsuleSpec requirements. |
| Linux containment starts after another thread exists | A per-thread syscall boundary could leave other threads outside the boundary. | Handle __capsule-child before the normal worker thread and refuse when single-threaded state cannot be proved. |
| Linux target or guard status protocol is incomplete | Execution remains unconfirmed or the supervised tree is killed. | Require the exact observed, authorized, resumed, and EOF sequence. |
| A bound package input changes its digest or its target path loses held identity | The package launch is refused before the interpreter starts. | Seal and hash inputs. Compare public paths with held capabilities. |
| The untrusted project path names a denied credential area or the held copy is swapped | The project run is refused. If cleanup cannot be proven after copying, the receipt becomes partial. | Check the source against the shared deny set. Bind the child to the retained writable directory and record cleanup proof. |
| macOS requests an unsupported resource dimension | Aggregate resource coverage is degraded. | Refuse enforcing launches instead of claiming partial resource control. |
| Windows ACL, AppContainer, Job Object, or resume setup fails | The child is terminated and partial ACL changes are reverted. | Create suspended. Assign the Job before resume. Track cleanup guards. |
| Windows piped launch is requested by an enforcing caller | The upstream is not started. | spawn_piped fails closed because the Windows contained child does not expose piped handles. |
| A domain allow-list lacks raw-socket blocking or broker proof | The child does not receive an end-to-end egress promise. | Keep domain_proxy_enforced false until both the OS boundary and broker are verified. |
Key files
| File | Why to read it |
|---|---|
| crates/…/mod.rs | Defines the shared capsule specification, coverage ledger, filesystem policy, presets, backend interface, and fail-closed requirements. |
| crates/…/capsule.rs | Provides backend selection and the completed, piped, supervised, and content-bound CLI launch seams. |
| crates/…/linux.rs | Describes Linux coverage and the child-side Landlock and seccomp boundary. |
| crates/…/macos.rs | Describes Seatbelt policy construction and the honest macOS coverage limits. |
| crates/…/windows.rs | Describes the portable Windows launch plan, ACL grants, AppContainer identity, Job limits, and command-line boundary. |
| crates/…/capsule_child.rs | Defines the hidden Unix launcher, descriptor-based handoff, achieved-coverage report, and bound-directory protocols. |
| crates/…/capsule_windows.rs | Applies the Windows plan and manages process, Job Object, ACL, profile, and temporary-home cleanup. |
| crates/…/capsule_proxy.rs | Defines the loopback egress broker and its per-connection policy checks. |
| crates/…/capsule_run.rs | Defines the fail-closed untrusted-project preset, private project copy, result receipt, and cleanup state. |
| crates/…/run.rs | Shows how live reviewed script execution enters the capsule. |
| crates/…/gateway.rs | Shows the deny-network piped launch used for an upstream MCP server. |
| crates/…/pkg_install.rs | Shows the content-bound package launch and its platform refusal contract. |
| crates/…/temp_run.rs | Shows the explicit best-effort degraded mode for filesystem-impact previews. |