Contained execution and runtime boundaries
Contained execution gives Guard a fail-closed path for local commands and read-only inline programs that need limited host access. Guard prepares the request, admits only a verified command identity, runs it inside a bounded process or workspace, and returns status and output evidence to the decision flow.
Execution lifecycle
Preparation
Preparation turns a launch request into an exact local execution. Guard requires a real canonical workspace, rejects work below protected system roots, and keeps only the environment values needed for stable presentation. The launch names one supported local Node, TypeScript, or package-script action rather than an open-ended shell command.
The preparation step resolves the real runtime executable without selecting Guard's own shim. This gives the later boundary a path-pinned runtime and a clean environment. Direct routes also carry an execution profile so the request matches the boundary that can enforce it.
References: src/…/contained_execution_common.py• L8-26 rust/…/flows.rs• L23-75 rust/…/package_launch.rs• L83-116
Admission
Admission checks that the launch describes exactly one supported local execution and that its identity is complete. The manager, workspace, runner, package data, source inputs, and launch arguments must agree before Guard can pass the request to the contained runner.
Guard binds the request to digests for the workspace inputs and executable files. If a path changes, the identity is incomplete, or the command is not one supported local action, the handoff returns to Guard review instead of running without containment.
Inline evaluation applies the same rule to direct python -c, node -e, and Bun evaluation. A script path must resolve inside the workspace. A program receives Git only when its command text names a trusted Git executable and the repository metadata belongs to that workspace.
References: rust/…/package_launch.rs• L44-107 rust/…/flows.rs• L120-177 rust/…/contained_inline.rs• L4-43 rust/…/inline_git.rs• L37-85
Supervision
Supervision runs the admitted request through one native contained decision path. The boundary receives the canonical workspace, cleaned environment, protected inputs, runtime identity, and time limit as one request. It produces a typed result only when the execution remains within that contract.
Workspace-write work uses a separate controlled workspace path. A broad command is not treated as a safe write merely because it names a directory. Guard ties changes to an approved operation and checks the result before it can affect the real workspace.
Wrapped commands use a native wrapper plan that identifies the core command, its execution directory, and any allowed output behavior. The runtime rechecks that plan before it runs the core. It does not peel an unsupported wrapper or let a wrapper create a new contained authority.
The native plan names every executable that the child may start. An inline program that reads the repository through Git adds only a trusted Git binary and the repository metadata that belongs to the admitted workspace.
References: rust/…/flows.rs• L94-114 rust/…/flows.rs• L186-207 rust/…/contained_workspace_sink_wrapper.rs• L31-62 rust/…/contained_wrapper_plan_op.rs• L21-63 rust/…/inline_git.rs• L91-129
Evidence collection
Evidence collection turns the bounded run into a result that Guard can use for its decision and receipt paths. The result keeps the operation identity and execution outcome together with the inputs and executable identity that defined the admitted run.
For a wrapped command, Guard captures the core output before it applies an allowed output chain. Line and byte limits are applied in the same order as the issued wrapper. Other stages read only captured standard input and use trusted local binaries. The final status and any status label preserve the shell-visible result, while a filter failure remains a containment failure.
The contained path treats a failed command as a command result when the selected operation permits any exit status. TypeScript checks require a zero exit. This distinction lets Guard report a real diagnostic result without confusing it with a failure to enforce the boundary.
References: rust/…/flows.rs• L179-207 rust/…/flows.rs• L282-312 rust/…/flows.rs• L368-395 rust/…/contained_workspace_sink_wrapper.rs• L197-249 rust/…/contained_workspace_sink_filters.rs• L52-99
Contained execution classes
Command execution
Command execution is the general contained path for one exact local Node runner. It supports bounded checks such as a test, lint, or diagnostic tool when Guard can identify the local executable and all required workspace inputs.
The command does not gain permission to fetch a replacement package or select an alternate runtime. A change in the runner, manifest, lock data, or protected workspace snapshot stops the run before the process starts.
References: rust/…/package_launch.rs• L44-71 rust/…/flows.rs• L120-207 rust/…/contained.rs• L277-327
Package-script execution
Package-script execution contains one exact local script through the package manager named by the launch. The script runner must stay inside the workspace, and its package and manifest identity must match the evidence captured before execution.
The package path is therefore a controlled local action, not a general package-manager shell. Unsupported manager input, more than one local execution, or any identity drift returns the request to review.
References: rust/…/flows.rs• L315-395 rust/…/package_launch.rs• L83-107
Node execution
Node execution runs one exact local tool through npx or bunx. Guard accepts a path-pinned native Node or Bun runtime only when it is a trusted local installation under a consulted caller home. Supported version-manager layouts and linked manager roots are included. Guard still checks the local runner and workspace inputs before starting the selected script.
The package-shim boundary has a special fail-closed rule for Vitest. If an allowed Vitest handoff cannot be contained, Guard refuses it rather than allowing the call to fall through to an uncontained process.
References: rust/…/package_launch.rs• L20-71 rust/…/package_launch.rs• L126-145 rust/…/flows.rs• L120-207 rust/…/contained.rs• L86-238
TypeScript execution
TypeScript execution contains one local npx tsc compiler check. The compiler must be the workspace's installed TypeScript package, and the launch must provide complete compiler and source evidence.
Guard protects both the compiler package and the source closure used by the check. This prevents a typecheck request from silently switching to a different compiler or reading files outside the admitted workspace inputs.
References: rust/…/package_launch.rs• L49-80 rust/…/flows.rs• L215-312
Inline evaluation
Inline evaluation contains a direct Python, Node, or Bun program as a read-only workspace action. It reuses the runtime and workspace boundary, then rejects a command shape that is not direct inline evaluation or a named script outside the workspace.
When the program names Git to inspect the work tree, Guard adds the trusted Git executable to the child allow-list. It grants linked repository metadata only when the metadata points back to the admitted worktree. Git cannot turn this read path into a write, network, or arbitrary process path.
References: rust/…/contained_inline.rs• L4-89 rust/…/inline_git.rs• L23-85 rust/…/inline_git.rs• L91-161 rust/…/inline_git_tests.rs• L48-98
Git inspection
Git inspection is a contained read-only route for commands that examine repository state. Guard resolves each requested directory change inside the workspace, trusts the Git executable, and grants only the worktree and safely related repository metadata as read roots.
The route disables Git prompts, optional locks, system configuration, and lazy fetch. A linked worktree can read its shared repository only when its metadata proves that it belongs to the admitted worktree. An unrelated repository is not granted through a .git pointer.
References: rust/…/git_plan.rs• L34-151 rust/…/git_plan.rs• L154-238 rust/…/inline_git.rs• L132-161
Workspace-write execution
Workspace-write execution covers approved operations that may change workspace state. The operation is kept separate from read-only local checks so that a command cannot gain write authority only by appearing to run below the workspace root.
The write result remains subject to Guard's status, receipt, and effect checks. Promotion occurs only after the contained operation proves that it followed the approved scope.
References: rust/…/flows.rs• L94-114 rust/…/flows.rs• L197-207
Wrapped command execution
Wrapped command execution supports a narrow set of shell forms around a contained core. Guard can preserve directory changes, standard-error merging, output shaping, and status reporting without giving the wrapper control over admission or the process boundary.
The wrapper plan is created by the same native authority that classifies the request. A contained receipt is required before the runtime peels the wrapper. A read-only core may run from the workspace root or from an approved sibling repository root. A wrapper that is refused, nested, or outside those roots stays on Guard's normal sink path instead of being treated as contained.
Allowed output stages operate on the core's captured bytes. head and tail shape the bytes or lines directly. Other supported stages receive only standard input and run from trusted system or user-owned installations. They cannot open a file, use a pattern file, recurse, or extend the process plan.
References: rust/…/contained_wrapper_plan_op.rs• L40-97 rust/…/contained_workspace_sink_wrapper.rs• L86-180 rust/…/contained_workspace_sink_wrapper.rs• L261-287 rust/…/contained_workspace_sink_filters.rs• L70-99 rust/…/contained_output_match.rs• L21-63
Runtime boundaries
Filesystem boundary
The filesystem boundary anchors each run to one existing canonical workspace. It rejects aliases, symlinked workspace roots, system-root workspaces, external package trees, and runner paths outside the workspace. A peeled read-only wrapper can use an approved sibling repository root only when the native plan proves that the directory belongs to that repository.
This boundary makes the workspace snapshot meaningful. The command can run only when the files used to identify the operation still match the evidence that Guard admitted. A directory below an approved root does not expand the root or change the authority of the contained receipt.
References: src/…/contained_execution_common.py• L12-20 rust/…/flows.rs• L36-75 rust/…/flows.rs• L132-177 rust/…/git_plan.rs• L79-122 rust/…/contained_workspace_sink_wrapper.rs• L166-180
Process boundary
The process boundary is the native enforcement point for the admitted request. It limits the child to the selected workspace inputs, cleaned environment, runtime identity, and execution lifetime, then returns a typed outcome to Guard.
The caller does not keep a separate approval that could outlive the native decision. If enforcement cannot start or prove the requested run, the contained path returns no result and the request remains subject to Guard review.
The process allow-list also controls child processes started by inline code. A Git child is available only when the plan explicitly names it. Other unapproved process starts fail inside the contained boundary. Output filters are a separate, bounded stage: they run only after the core has finished, receive captured standard input, and stop on timeout or output-budget failure.
References: rust/…/flows.rs• L94-114 rust/…/flows.rs• L186-207 rust/…/package_launch.rs• L1-8 rust/…/inline_git.rs• L91-129 rust/…/contained_workspace_sink_filters.rs• L142-243
Environment boundary
The environment boundary prevents a contained child from inheriting arbitrary host state. Guard removes secrets, credentials, proxy settings, and host path controls. It then supplies private home and temporary paths, a path made from allowed executables, and selected safe settings.
For broader workspace actions, Guard gives tools private writable cache locations and reads host caches through explicit grants. It disables network fetches and automatic version changes where the tool supports them. This keeps dependency use local without giving the child a path to modify host state.
Git-enabled children receive fixed Git settings that prevent prompts, optional locks, system configuration, and lazy fetch. The same filtered environment is used for inline programs and their allowed Git child. Output filters clear the inherited environment and keep only a fixed executable path plus locale settings needed for stable text processing.
References: src/…/contained_execution_common.py• L8-26 rust/…/flows.rs• L47-62 rust/…/environment.rs• L5-125 rust/…/environment.rs• L126-217 rust/…/inline_git.rs• L13-21 rust/…/contained_workspace_sink_filters.rs• L172-185
Execution flow
The flow below shows how a package launch or direct hook request becomes a bounded result or returns to Guard review. A supported wrapper is peeled into a contained core before its output is gathered and shaped.
flowchart LR
A[Package launch or direct hook] --> B[Parse one local execution]
B -->|Unsupported or incomplete| C[Guard review]
B --> D[Check profile, workspace, and runtime]
D -->|Identity, profile, or path drift| C
D --> E[Protected input snapshot]
E --> F[Native contained request]
F -->|Enforcement fails| C
F --> G[Bounded core process]
G --> H[Allowed output shaping]
H --> I[Typed execution evidence]
References: rust/…/package_launch.rs• L54-107 rust/…/flows.rs• L120-207 rust/…/contained_inline.rs• L44-89 rust/…/contained_workspace_sink_wrapper.rs• L125-154
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the supported manager and one-execution rules aligned with package-intent parsing and package shims.
- Keep canonical workspace checks aligned with snapshot paths, external package rejection, and system-root policy.
- Keep runtime lookup separate from Guard shims and keep cleaned child environment rules aligned with native request construction.
- Keep executable, package, lock, manifest, source, and launch digests bound to the same operation evidence.
- Keep Vitest refusal behavior fail-closed when a package-shim handoff cannot prove containment.
- Keep inline script paths and Git grants tied to the same workspace admitted by the runtime plan.
- Keep linked-worktree metadata checks tied to the workspace pointer. Do not grant an unrelated repository through
.git. - Keep exit-status policy aligned with the meaning of each result type. A diagnostic result may allow a non-zero exit, while a typecheck must not.
- Keep direct-route profile names, normalized hook fields, host support, and contained request schemas aligned across routing and native execution.
- Keep wrapper peeling, sibling-root checks, output-stage grammar, and contained receipts driven by the same native plan.
- Keep output filters stdin-only, bounded by timeout and output size, and resolved to trusted binaries rather than caller
PATH.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The workspace is an alias, symlink, or lies below a system root. | The process could run under a root that the policy did not assess. | Reject the workspace before building the contained request. |
| The launch names an unsupported manager or more than one local execution. | The contained runner cannot prove which action it will run. | Return to Guard review without starting a process. |
| The runner, compiler, manifest, lock data, or source snapshot changes. | The approved evidence no longer describes the command inputs. | Compare the current identity with the captured digests and stop on drift. |
| The runtime exists under a different caller home or outside a supported installer layout. | A real local runtime could be refused, or an untrusted executable could enter the contained path. | Consult the request and account homes, canonicalize manager roots, and admit only supported runtime shapes. |
| Runtime lookup selects a Guard shim. | The shim could replace the runtime or alter the command handoff. | Exclude the shim directory and require a canonical native executable. |
| A direct inline script is outside the workspace. | The contained program could load an unapproved file. | Reject the plan before the process starts. |
| An inline program names an untrusted Git or a forged repository pointer. | The program could read an unrelated repository or run a workspace-provided executable. | Grant only trusted Git and metadata proven to belong to the workspace. |
| A wrapper is nested, refused, or runs from an unapproved directory. | The runtime could execute text that the receipt did not cover. | Require a native wrapper plan and a matching contained receipt. |
| An output stage names a file, pattern file, recursion, or an unsupported program. | The filter could read outside captured output or extend the process path. | Enforce the shared stdin-only stage grammar before any filter runs. |
| A trusted output filter is missing, times out, or exceeds its output budget. | Guard cannot reproduce the wrapper's output or safely gather its evidence. | Return a contained output-filter failure and do not treat the result as complete. |
| Containment fails for a Vitest package-shim handoff. | The allowed launch could fall through to an uncontained process. | Return an explicit refusal instead of a normal review fallback. |
| The native contained request cannot enforce its boundary. | The command would have no proof of restricted execution. | Return no contained result and keep the request in Guard review. |
| A direct route has a missing or mismatched profile, malformed input, or unsupported event. | The hook cannot prove that the requested action matches the contained route. | Leave the request unrouted and keep the containment-required decision in force. |
Key files
| File | Why to read it |
|---|---|
| rust/…/package_launch.rs | Shows how package-shim input becomes one supported local Node or TypeScript launch and how fail-closed outcomes are selected. |
| rust/…/flows.rs | Shows the shared workspace, runtime, evidence, snapshot, and native-request flow for Node, TypeScript, and Bun scripts. |
| rust/…/contained.rs | Defines native preparation and trust checks for contained Node and Bun test runs. |
| rust/…/contained_inline.rs | Defines the read-only boundary for direct Python, Node, and Bun evaluation. |
| rust/…/contained_vitest.rs | Defines local runner admission for Vitest and related test tools. |
| rust/…/environment.rs | Defines the filtered child environment and private tool-cache behavior. |
| rust/…/git_plan.rs | Defines protected Git inspection and safe repository metadata roots. |
| rust/…/inline_git.rs | Connects inline programs to trusted Git and bound repository read roots. |
| rust/…/contained_wrapper_plan_op.rs | Exposes the native wrapper plan that keeps classification and runtime peeling on one contract. |
| rust/…/contained_workspace_sink_wrapper.rs | Runs contained cores and preserves approved wrapper output and status behavior. |
| rust/…/contained_workspace_sink_filters.rs | Applies bounded output stages over captured core output and verifies filter binaries. |
| rust/…/contained_output_match.rs | Exposes the validated output-matcher boundary for the Python sink. |
| src/…/contained_execution_common.py | Defines shared canonical-workspace and child-environment rules. |
| docs/guard-decision-and-enforcement.md | Explains the parent decision flow that consumes contained execution outcomes. |
| docs/runtime-hooks-proxies-and-shims.md | Explains the shim boundary that can hand package launches into contained execution. |