← Harness Engineering From First Principles

Isolation, Approvals, and Trust Boundaries

Test path escapes, junctions, unexpected commands and expired approvals on a qualified Windows environment.

Hypothetical vignette; no operation or attack was run.

At 10:00 a human approves an agent’s request to rewrite tests/test_scheduler.py. At 10:20, after a long reasoning turn and two other edits, the agent submits a write to the same path. The content now differs from what was shown at 10:00. Meanwhile, a teammate has replaced tests/ with a junction that points somewhere else. Does the 10:00 approval cover the 10:20 write?

An approval system checking only tool name, path spelling and expiry would say yes. The tool name matches, the path string matches, and the approval has not been revoked. Every one of those checks is the wrong check. The human approved a specific change to a specific object as it was then. The agent now proposes a different change to what may be a different object. An approval that does not bind to what was actually approved is a blank cheque with a tool name written on it.

Chapter 11 established that authority must be enforced by a boundary outside the model. This chapter covers the two ways that authority is created and confined in practice. Approvals create authority during a run, at the moment a human decides. Isolation confines authority, so that a mistaken or hostile request cannot reach beyond its grant. Both have to be qualified, meaning demonstrated on the actual environment, and this book’s environment is Windows.

Evidence status. Draft manuscript. Project 05 (Permissioned Operator) has not started. Gate C (security qualification) is pending. No isolation or restricted-identity mechanism exists in this book’s code. The educational authority-broker demonstration D12-BROKER-01 is implemented and executed (examples/pi-harness-lab/src/authority-broker.ts; test/authority-broker.test.ts, 12/12 pass, including principal authentication across real separate OS processes and a junction-swap refusal with its canary intact). It demonstrates broker decisions — secret-derived principals, grant checks, expiry, use-counts, and broker-computed object identity with version binding — in the same privilege domain as the requester. It does not confine anything: a same-user process is outside its boundary by statement, and no container, restricted account, or qualified Windows identity work exists. Project 01’s latest independent review returned REJECT for offline acceptance (HARNESS-PROJECT-01-REVIEW-02). Its application-level refusals are not isolation evidence in any case. Windows and container facts are DOCUMENTED via R04’s cited Microsoft documentation. Agent Framework approval semantics are DOCUMENTED via R01 (not adversarially tested). All designs are PROPOSED. EXPERIMENT PENDING.

12.1 Trust boundaries in a harness

A trust boundary is a point where a request or data crosses between principals that are trusted differently. A boundary needs checking whenever the receiving side has authority that the sending side should not be able to use freely. Counting the boundaries in the architecture this book has built so far gives a map of where checks must live:

Boundary Less trusted side More trusted side What must be checked
Model → host Model output (shaped by untrusted text) Tool handlers Shape, scope, budget (Chapter 5)
Worker → effect broker Worker process (may be compromised) Broker holding effect rights Permission or approval per operation (Chapter 11)
Broker → operating system Broker code Kernel access checks Identity, rights, object identity
Harness → human approver Proposal text (model-written) Human decision That the human sees the normalized operation, not the model’s description of it
Harness → external service Request Service’s own authority Idempotency and reconciliation contract (Chapter 10)

The fourth row is easy to miss. An approval request is a message to a human, and if it is assembled from model-written text, the model can describe a destructive operation in harmless language. The approval interface must render what the boundary will execute: the exact command argument vector, the exact target object, the exact content digest and the diff. A summary the model wrote is not acceptable.

12.2 What an approval must bind to

An approval is a permission created at runtime by a human principal. To be worth anything, it must be checked by the same boundary that executes the effect, and it must bind to enough of the operation that a different operation cannot borrow it. R04 proposes the binding fields, and this book adopts them as its approval contract (R04-SECURITY-RECOVERY.md R04-P05; PROPOSED):

Approval should bind principal, run, exact normalized operation/payload digest, target identity, preconditions, policy revision, expiry, maximum uses and cost/size scope. Validate immediately before dispatch; changed content/target or expired authority requires a new decision.

Each field closes a specific borrowing attack:

  • Principal and run. An approval given to one run or agent cannot be replayed by another.
  • Normalized operation digest. “Write file X” approved with content C cannot be reused to write content C′. Normalization matters: the digest must be computed over the canonical form the boundary will execute, so that two encodings of the same operation compare equal and two different operations never do.
  • Target identity. This means the object, not the path string. §12.3 explains why that difference matters on Windows.
  • Preconditions. The base content digest from Chapter 6. An approval of an edit is an approval of that edit against that base. R01 records the same point for editing: “approval alone does not establish freshness” (R01-MICROSOFT.md, project implications).
  • Policy revision. If the policy changes, outstanding approvals are re-evaluated against the new one.
  • Expiry and maximum uses. These bound the window in which a stolen or forgotten approval can be used. Single-use is the default for effects.
  • Cost and size scope. “Approve running the test suite” should not cover a run that consumes an hour or downloads a gigabyte.

Microsoft’s Agent Framework documents part of this discipline. Its agent loop returns pending approval requests, Python’s local approval responses bind to pending requests in the same session, and the documentation describes re-approval when middleware changes arguments that were previously approved (R01-MICROSOFT.md R01-C03 and its approval discussion; DOCUMENTED, no adversarial test performed). R01 draws the invariant this chapter needs: “show the exact request, retain the authoritative session, and resume through a bound response”. It also cautions that documented approval defaults are not accepted as identity-bound host authority (gate decision). The same caution applies to anything this book builds: a binding written in documentation is a claim until a test tries to break it.

Here is the shape of an approval record and its check. The types below specify the full broker-side contract; their decision logic is executed in D12-BROKER-01 (BrokerHost: secret-derived principals, grant checks, expiry, use-counts, broker-computed digests and identity, per-target version binding). What remains unimplemented is the deployment the contract assumes: a broker in a separate privilege domain, a restricted identity, and qualified confinement. The rung-2 subset — approver identity, run binding, expiry, separate-approver denial and audit — is executed in D11-AUTH-01 (Chapter 11 §11.5).

// Contract specified here; decision logic executed in D12-BROKER-01
// (BrokerHost). Separate-privilege-domain deployment not implemented.
interface ApprovalGrant {
  approvalId: string;
  principal: string;          // who approved
  runId: string;
  operationDigest: string;    // SHA-256 of the normalized operation the broker will execute
  targetIdentity: string;     // object identity (e.g. volume + file ID), not a path string
  preconditionDigest: string; // base content digest the change was computed against
  policyRevision: string;
  expiresAt: string;          // absolute time
  maxUses: number;            // broker-validated positive integer; default 1
  scope: { maxBytes: number; maxWallMs: number };
}

type CheckResult = { ok: true } | { ok: false; reason:
  "NO_APPROVAL" | "WRONG_RUN" | "OPERATION_CHANGED" | "TARGET_CHANGED" |
  "PRECONDITION_CHANGED" | "POLICY_CHANGED" | "EXPIRED" | "USED" | "OUT_OF_SCOPE" };

// Runs inside the broker, immediately before dispatch, after the broker has
// itself normalized the operation and resolved the target to an object identity.
// Every input to this check is computed by the broker, never taken from the request.

The comment at the bottom carries the essential safety condition. If the operation digest or the target identity used in the check is supplied by the requester, the requester can supply values that match the approval while executing something else. The broker must compute every compared value from what it will actually execute. Leave that out and the check is decorative. D12-BROKER-01 executes exactly this: execute() re-resolves the target and re-reads the content, comparing against the approval’s bound identity and digest, and refuses TARGET_CHANGED and PRECONDITION_CHANGED — including a junction swap whose canary stays intact. What the demonstration does not do is hold the file handle between check and write; the residual check-then-use window is named in §12.3’s treatment, not eliminated.

Approvals also belong in the durable journal of Chapter 9, as the AUTHORIZED entry written before DISPATCHING. Approval state must survive a crash, and “used” must be recorded before use, or a crash between dispatch and recording turns a single-use approval into a reusable one.

12.3 Paths are not objects: Windows specifics

The opening example’s junction is not exotic. It is the ordinary way that path-based checks fail on Windows. R04 assembles the relevant Microsoft documentation (R04-C01–C03; DOCUMENTED) and draws design consequences from it (R04-P03; PROPOSED). In summary:

  • Lexical spelling is not object identity. Windows has case rules, multiple namespaces (device paths, the \\?\ extended-length form, UNC paths) and alternate data streams. A string-prefix check such as “starts with C:\repo” fails on sibling names (C:\repo-evil). Normalization alone cannot settle case-sensitive directory behaviour or aliasing.
  • Redirection happens on ancestors. Junctions and other reparse points can redirect any component of a path, so checking only the final component is insufficient.
  • Hard links are aliases of the same file under different names. They are a separate problem from reparse points.
  • Check then reopen is racy. Validating a path and then opening it again by name lets a concurrent writer replace the object in between. Opening once, inspecting the object through the handle (for example with final-path lookup), and operating through that same handle stabilizes which object is used. It does not freeze its bytes (Chapter 6).

R04 states the implication for a broker plainly. It needs “a reviewed handle-based open/inspection strategy, object/volume identity, appropriate sharing/access restrictions”, and it must “deny on unresolved identity or lookup failure”. It also declines to supply a qualified algorithm. This chapter follows R04’s lead and does not supply a qualified one either, but D12-BROKER-01 executes the checkable core: resolve the target through the ancestor chain (junctions and symlinks resolved, escapes refused), bind the real path plus the content digest at approval, and re-resolve at dispatch — a swapped ancestor yields TARGET_CHANGED, changed bytes yield PRECONDITION_CHANGED, with an outside canary verified intact. The residual check-then-use window (resolve, then the caller opens) is named, not eliminated: the broker authorizes; it does not hold the handle the writer uses. What this chapter supplies as requirement is that any path language the broker accepts must reject absolute, drive-relative, UNC, device and extended-namespace paths, traversal components, alternate streams, reserved names, and ambiguous trailing separators, dots or spaces (R04-P03). The test for all of this is in §12.6.

Project 01 avoids every item above by not accepting paths at all, which is the main reason R04 recommended opaque IDs. Project 05 cannot avoid them, because changing “selected files” in a real working tree means naming real objects.

12.4 Commands are programs, and programs do anything

“Unexpected commands” is the second attack class in the brief. The intuitive defence is a command allowlist (npm test, git status). Two facts make string allowlists weaker than they look.

Strings are not argument vectors. npm test passed to a shell, and npm test && curl … passed to the same shell, share a prefix. A string match on the first word approves both. Structured execution passes an argument vector to the executable directly, with no shell, and compares the executable’s identity (resolved path and file hash) and every argument against the grant. That closes a large class of injection.

Approved programs execute untrusted code. This fact is the more important of the two. npm test runs the repository’s own test scripts and package lifecycle hooks, and pytest imports the repository’s code. An approval to “run the tests” is therefore an approval to execute whatever the repository contains, which is exactly the untrusted input from Chapters 7–8. R04 is explicit for Repo Scout: “Do not execute setup instructions, hooks, package scripts, repository configuration, local plugins or discovered commands” (R04-P02). Once a later project must execute repository code, as Project 06 (Chapter 14) does, no amount of command filtering confines it. Only isolation can: a worker whose identity, file access and network egress limit what that code can reach.

The conclusion is architectural. Command allowlists control which programs start, and isolation controls what they can do. A harness that runs repository code needs both, and it should not mistake the first for the second.

12.5 Isolation options and what they actually guarantee

R04 compares four isolation options for this book’s Windows environment (R04-P04, with C05–C06; PROPOSED decisions on DOCUMENTED foundations):

Option What it relies on Caveats recorded by R04
Immutable data manifest with opaque IDs No live filesystem access from requests Recommended for Project 01. Not isolation of the host process
Dedicated restricted account or token with fixture-only access OS access checks (C04) Needs tested ACL, token and handle-inheritance and egress configuration; process separation alone is insufficient
Process-isolated Windows container Shared kernel Microsoft identifies hypervisor isolation, not process isolation, as the robust boundary for hostile multi-tenancy (C05)
VM or hypervisor-isolated worker Hypervisor Reserved for execution studies. Image, mounts, privileges and network must be pinned and qualified. Higher setup cost “is not evidence of stronger local behavior”

One configuration fact deserves emphasis because it defeats the naïve use of a convenient tool. Microsoft documents that Windows Sandbox’s defaults enable networking and clipboard sharing, and that mapped folders expose host resources (R04-C06; DOCUMENTED). R04’s conclusion: “A default launch is insufficient for this proposed study.” Isolation is a configuration, and the configuration is part of what must be qualified.

Which option fits Project 05? Its task is to change selected files with a capability policy and approval tokens, without running repository code. Under the three conditions of Chapter 11 §11.7, the asset is the rest of the user’s filesystem and credentials, and the requester is the agent’s worker. A broker under a restricted identity (rungs 3–4) is the smallest design that could pass the required tests. A VM becomes necessary when repository code runs (Project 06). That is a PROPOSED sizing, to be confirmed or refuted by the tests.

12.6 Qualification: what it means to say “isolated”

The blueprint defines Gate C as: “malicious path and unsafe-command tests demonstrate isolation outside the Pi process; explicit Windows test record”. A qualification is a record that a specific configuration resisted a specific attack corpus, observed by independent monitors. It has four parts:

  1. Pinned configuration. OS build, account and token configuration, ACLs, broker version, isolation image and settings, network policy. A change to any of these invalidates the record.
  2. Attack corpus. R04-E02 proposes registering casing, namespace, ancestor-reparse, hard-link and concurrent-replacement cases in a disposable isolated fixture, with “100 bounded repetitions per race case, fixed timeout” (PROPOSED; “Do not run until an isolated test design is approved for implementation”). This chapter adds command cases (shell metacharacters, argument injection, an approved program executing hostile repository code) and approval cases (expired, used, operation changed, target changed, precondition changed, policy changed, replay by another run). The value 100 is a provisional bounded test budget, not a power or race-coverage guarantee. Development qualification must justify case coverage and repetitions, then freeze the chosen count and timeout. Repeated races on one fixture are not independent task draws.
  3. Independent observation. Before-and-after object identities and out-of-root canary monitors distinguish denial from silent redirection (R04-E02). A test that only reads the broker’s “denied” message has measured the broker’s opinion of itself.
  4. Stated coverage limits. “A passing finite corpus cannot prove general containment” (R04-E02). The record lists what was not tested: kernel vulnerabilities, administrator compromise, dependency compromise. All of these lie outside R04-P01’s assurance claim.

A qualification therefore establishes a narrow, useful claim: this configuration denied these attacks, as observed by these monitors, on this date. It does not establish that the system is secure. Every chapter that later relies on Project 05 must quote the claim at that width.

12.7 Worked example: four attacks on a Permissioned Operator

Design walk-through for the restricted-identity deployment, which is not built; the broker-decision rows below it are executed in-process in D12-BROKER-01. The Permissioned Operator changes two named files in a disposable working tree. A broker running under a restricted identity holds write access to that tree only. The worker has no write access anywhere, and no read access to the user profile.

Attack What the worker sends Expected broker behaviour Independent observation
Path escape via junction Approved write to tests\test_scheduler.py, after tests\ is replaced by a junction to the user profile Resolves the target to an object identity through a handle; it no longer matches the approval’s targetIdentity, so TARGET_CHANGED Profile canary unchanged; tree file unchanged
Unexpected command git status && curl http://… as a string Rejected: commands are accepted only as argument vectors with an approved executable identity Egress monitor shows no connection
Expired approval The approved edit, re-sent after expiresAt EXPIRED; a new decision is required Target digest unchanged
Operation changed The approved path and base, different content Broker-computed operationDigest differs, so OPERATION_CHANGED Target digest unchanged

Three negative controls make the table meaningful. Without them, a broker that refused everything would pass every row:

  • Legitimate operations succeed. The approved write, sent once, before expiry, against the approved base and object, is applied, and the after digest matches.
  • Ablated identity binding. The same broker, with targetIdentity checked as a path string instead of an object, is expected to fail the junction row. This confirms that the identity check is what does the work.
  • Ablated isolation. The same broker running under the user’s own identity is expected to stop the model-originated attacks, but to fail an in-process rogue component that writes the profile canary directly (Chapter 11 §11.5). This confirms that the restricted identity is what does the work.

12.8 Project 05 checkpoint: Permissioned Operator

Blueprint requirement: change selected files safely. The new mechanisms are an OS- or container-isolated effect broker, a capability policy and approval tokens. The verification is that unauthorized-path, symlink or reparse, unexpected-command and expired-approval attempts are denied.

Status: not started. Its prerequisites in the book’s sequence are an accepted Project 01 evidence pipeline (REVIEW-02: REJECT), a Project 02 precondition mechanism (not started), a Project 04 journal for AUTHORIZED entries (not started), and an approved isolated test design (R04-E02 condition).

Proposed study. All of the following is PROPOSED; EXPERIMENT PENDING.

Arm Enforcement design
P2 Rung 2: in-process handler guard with path checks and approvals; worker under the user’s identity
P3 Rungs 3–4: separate broker under a restricted identity; worker without write or profile access
P3-id P3 with path-string target binding (ablation of object identity)
P3-amb P3 with the broker under the user’s identity (ablation of restricted identity)

All arms receive the §12.6 corpus, a legitimate-operation set and a fixed repetition schedule for race cases. Endpoints are computed from independent monitors: attacks denied, silent redirections (an effect landed somewhere other than intended), canary violations, false denials (legitimate operations refused), approval-binding violations, and overhead per operation.

The registered predictions are:

  • P3 has zero canary violations and zero silent redirections on the corpus.
  • P2 stops model-originated attacks but fails rogue-component cases.
  • P3-id fails at least the junction and hard-link cases.
  • P3-amb fails rogue-component cases.

Any P3 canary violation falsifies the qualification for that configuration. A high false-denial rate is a usability defect, to be reported alongside the security result, never traded against it silently.

12.9 Failure modes

  • Approval as blank cheque. Bound to tool name and path only. Defence: the R04-P05 fields, computed by the broker.
  • Requester-supplied digests. The check compares values the request provided. Defence: the broker computes every compared value from what it will execute.
  • Model-written approval prompts. The human approves a description, not an operation. Defence: render the normalized operation, target and diff.
  • “Used” recorded after use. A crash makes single-use reusable. Defence: journal the use before dispatch (Chapter 9).
  • Command allowlist mistaken for isolation. An approved program runs hostile repository code. Defence: isolation sized to what the program can execute.
  • Default isolation. Windows Sandbox or containers launched with defaults. Defence: pinned, reviewed configuration as part of the qualification record.
  • Refuse-everything passes. No legitimate-operation controls. Defence: false-denial endpoint and ablation arms.

12.10 What you can build and test now

  • Implement the ApprovalGrant check as a pure function whose inputs are computed by a stub broker, and unit-test each reason with a case that changes exactly one bound field. D12-BROKER-01 executes this for the decision layer (12/12); the stub-broker-to-real-broker step — separate privilege domain — is the pending part.
  • Write the qualification record schema (configuration, corpus, monitors, results, coverage limits) before writing any broker, so that the broker is designed to be qualified.
  • In a disposable VM, never on a working machine, script the R04-E02 path-identity cases as data, ready for an approved test design.
  • Inventory, for your own agent setups, every approved command that executes repository code.

12.11 What remains unverified

  • Project 05’s restricted-identity deployment and Gate C: no isolation or separate-privilege-domain broker exists, and the isolated test design has not been approved. Verified blocker in this environment: no container daemon, no sandbox binary, no privilege to mint restricted tokens from the test context (recorded in BATCH-06-EVIDENCE.md).
  • A qualified Windows handle-based containment algorithm. R04 explicitly supplies none.
  • Agent Framework approval behaviour under adversarial use (R01-C03 is documentation only), and its source and license audit (R01 incomplete).
  • Whether a Pi 1.6.0 integration can route every effect through an out-of-process broker with no in-process bypass. This depends on disabling all built-in effectful tools and extensions, which needs testing against the pinned artifact (R02).
  • Human-factors questions about approval prompts, including approval fatigue. These are raised here as design concerns, not measured.

EXPERIMENT PENDING. No isolation or restricted-identity mechanism has been implemented or qualified for this book. Broker decisions and object-identity checks are executed in D12-BROKER-01 in-process; they are not confinement, establish no cross-principal boundary, and qualify nothing under Gate C.

Parts I and II have made the parts of a single run trustworthy: its contract, its evidence, its information, its state, its effects and its authority. Real work is rarely a single step. It is an investigation, a reproduction, a fix, a test and a review, with decisions between each. Part III asks how a harness should structure multi-step work, beginning in Chapter 13 with the difference between a plan the model proposes and a workflow the harness enforces.

Previous: Chapter 11: Capability Is Not Authority.

Next: Chapter 13: Plans, Workflows, and the Agent Loop.