Runtime and operations
AgentShield extends security analysis beyond a one-time scan. It can enforce rules while an agent is active, provide a contained MiniClaw service for agent sessions, and turn findings into reports, fixes, evidence, and change alerts. The runtime protects the point of action while the operational services help people understand and respond to the result.
System boundary
The runtime and operations layer sits after security analysis and around active agent use. It accepts policy and scan results as control inputs, then produces protected execution, visible security events, and outputs that support review or follow-up.
The two main paths have different jobs:
- The runtime path checks tool activity or contains a MiniClaw session before the activity can affect its environment.
- The operations path presents findings, applies safe changes, packages evidence, and detects security drift over time.
These paths complement the static and active analysis systems. Analysis describes risk. Runtime controls reduce immediate risk. Operations make the result usable by engineers, owners, CI systems, and review processes.
The child pages provide the next level of detail: Runtime and MiniClaw services covers active enforcement and sessions, while Reporting remediation and monitoring covers outputs and follow-up work.
References: src/…/index.ts• L1-16 src/index.ts• L269-296 src/index.ts• L899-909
Runtime enforcement
Runtime enforcement connects an agent harness to an AgentShield policy through a pre-tool-use check. A tool call is considered against deny rules before execution, and the result can be recorded as an allow or block decision for later review.
The runtime policy expresses the main control points:
| Control | Purpose | Operational result |
|---|---|---|
| Deny rules | Stop a tool or matching input | The call is blocked with a reason |
| Logging | Record the decision and timing | An append-only NDJSON trail supports review |
| Policy validity | Confirm the policy can be used | Status reports whether the monitor is ready |
Installation adds the runtime check to the target settings and creates a default policy when needed. Repair backs up unreadable configuration before it restores a usable setup. Status gives a health view that distinguishes a missing install from a missing or invalid policy. This makes runtime failure visible instead of treating setup as proof that enforcement is active.
The runtime also has a deliberate removal path. Uninstall removes the AgentShield hook without describing the target as protected afterward, so callers can treat removal as a change in security posture.
References: src/…/install.ts• L90-181 src/…/install.ts• L184-287 src/…/status.ts• L15-106 src/…/evaluator.ts• L9-46
MiniClaw execution boundary
MiniClaw is a small agent service that places each session inside a short-lived sandbox with a fixed tool set. The sandbox creates a private, owner-only session directory and makes filesystem access pass through path, symlink, file-type, and size checks. This keeps untrusted prompts and agent actions inside a narrow boundary while exposing enough session state for a client or dashboard to understand what happened.
The session boundary combines several protections:
- A private sandbox directory contains session files.
- A tool whitelist limits which actions are available. Safe, guarded, and restricted tools represent increasing risk.
- Path checks prevent traversal and symlink escape from the sandbox.
- File extension and size checks limit the kinds of files and the amount of data a session can create or read.
- Session duration, request size, network policy, and server rate limits limit resource and data exposure.
- Prompt input is sanitized before routing and responses are filtered before they leave the service.
- Security events record blocked prompts, denied tools, sandbox violations, timeouts, rate limits, and filtered responses.
The HTTP service manages session creation, prompt routing, session listing, session deletion, event retrieval, and health checks. Sessions are held in memory and are destroyed when they end or when the server stops. MiniClaw currently supplies the security envelope and a deterministic fallback response; a future model backend must remain inside that envelope.
The detailed service contract and security boundaries are documented in Runtime and MiniClaw services.
This diagram shows how a MiniClaw request moves through the active protection boundary and returns both a response and security context.
flowchart LR
Client[Client prompt] --> Server[MiniClaw service]
Server --> Session[Active session]
Session --> Sanitize[Input sanitization]
Sanitize --> Tools[Whitelist and sandbox checks]
Tools --> Route[Prompt routing]
Route --> Filter[Output filtering]
Filter --> Response[Protected response]
Sanitize -.-> Events[Security events]
Tools -.-> Events
Filter -.-> Events
Events --> Audit[Session event view]
References: src/…/types.ts• L15-36 src/…/types.ts• L97-139 src/…/types.ts• L158-225 src/…/server.ts• L185-335 src/…/router.ts• L302-391 src/…/sandbox.ts• L41-82 src/…/sandbox.ts• L91-113 src/…/sandbox.ts• L127-152 src/…/sandbox.ts• L169-194 src/…/sandbox.ts• L209-243
Security result lifecycle
Operational services move a security result from discovery to action and later review. A scan creates findings and a score. The result can then be rendered for a person, consumed by an automation system, changed through safe remediation, or compared with a later scan.
The main result forms serve different audiences:
| Result form | Main use |
|---|---|
| Terminal, Markdown, or HTML report | Human review and status sharing |
| JSON report | Scripts and service integrations |
| SARIF report | Code-scanning and CI systems |
| Evidence pack | Portable audit and security-review handoff |
| Remediation plan or fix summary | Work assignment and change review |
| Baseline drift and watch alert | Ongoing change detection |
The reporter surface exposes the score and defense summary together with terminal, structured, web, and code-scanning report forms. These outputs let the same security result move between a person, an automation system, and a CI review without changing its meaning.
The evidence pack joins the main report with policy status, baseline comparison, supply-chain results, CI context, and remediation data. It hashes its artifacts so a receiver can verify that the bundle was not changed after creation. Fleet inspection then routes packs toward security blockers, policy review, baseline review, supply-chain review, or a ready state.
The score is a summary signal rather than a replacement for findings. It starts from category scores and weights deductions by severity and confidence. Reviewers should use the findings and their evidence to decide what action is safe.
References: src/…/index.ts• L1-6 src/…/score.ts• L15-31 src/…/index.ts• L281-419 src/…/index.ts• L421-619
Change monitoring
Watch mode keeps operational results current after the initial scan. It establishes a baseline, observes configured directories for changes, rescans after a quiet period, and compares the new result with the prior finding set.
When the comparison finds new or resolved findings, or a score change, the watcher records drift and can send a terminal alert, a webhook alert, or both. Fingerprints let it distinguish a new issue from an issue that remains the same even when other scan data changes. The command can also stop at startup when the initial result contains critical findings for a CI use case.
This makes monitoring a feedback loop rather than a second reporting format:
- The initial scan establishes the accepted view of the target.
- A file change triggers a debounced scan.
- The new result is compared with the baseline.
- Drift is exposed to operators through the selected alert path.
- The new result becomes the basis for the next comparison.
The detailed alert payloads and remediation handoffs are documented in Reporting remediation and monitoring.
References: src/…/watcher.ts• L24-101 src/…/watcher.ts• L168-231 src/…/diff.ts• L7-57 src/…/alerts.ts• L7-18 src/index.ts• L899-998
Change checklist
When these files or sections are changed, remember to consider these:
- Keep runtime installation, runtime status, and runtime repair aligned on the same hook marker, settings location, policy location, and health meanings.
- Keep the runtime policy schema and the active enforcement path aligned so a valid policy does not advertise controls that the live check cannot apply.
- Preserve the MiniClaw sequence of input sanitization, session checks, tool authorization, sandbox checks, and output filtering for every new request path.
- Keep sandbox path, symlink, extension, size, and cleanup guards aligned with every filesystem tool that uses a session directory.
- Keep security event types consistent across the session model, server event retrieval, and any dashboard or audit consumer.
- Keep report fields, SARIF properties, evidence-pack summaries, and fleet routing aligned when finding or policy result shapes change.
- Keep baseline fingerprint inputs stable when finding fields change, or existing drift comparisons can classify unchanged issues as new ones.
- Keep watch alert modes and webhook payload fields compatible with downstream receivers.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The runtime hook is missing | Active tool calls do not pass through AgentShield enforcement | Run runtime status checks and install the hook before relying on runtime protection |
| Settings or runtime policy JSON is invalid | The monitor is not ready, and installation stops rather than modifying a broken settings file | Use runtime repair; it backs up invalid files before rebuilding the monitor |
| A policy file is missing or cannot be loaded | Status reports a problem, while the policy loader falls back to its default allow-all policy | Treat ready status as a deployment condition and inspect policy validity before use |
| A requested path traverses the sandbox or reaches a symlink outside it | The filesystem operation is rejected and the session cannot use that path | Resolve and validate the path before access, including a real-path check for existing targets |
| A session creates a disallowed or oversized file | The file operation is blocked or the resource limit is reached | Apply extension and size checks before the operation |
| A MiniClaw session exceeds its duration or its sandbox cleanup fails | The request can expire, or orphaned session files can remain | Enforce session time limits and inspect cleanup or server-stop results |
| A client exceeds request or IP limits | The service rejects the request before prompt work begins | Use the health endpoint for liveness and tune limits for the expected client load |
| A report or evidence artifact is changed or missing | Reviewers may use incomplete or untrusted security results | Verify the evidence pack before inspection or fleet routing |
| A watched target changes and introduces new findings | The baseline no longer describes the current security posture | Review the drift alert and fix, roll back, or explicitly accept the change |
Key files
| File | Why to read it |
|---|---|
| src/…/index.ts | Public boundary for policy loading, evaluation, installation, repair, and status |
| src/…/install.ts | Runtime monitor lifecycle and safe recovery behavior |
| src/…/status.ts | Readiness states used by operators and checks |
| src/…/evaluator.ts | Tool-call decision and runtime log contract |
| src/…/index.ts | Public MiniClaw entry points for standalone and embedded use |
| src/…/server.ts | Session, request, event, health, and shutdown service flow |
| src/…/router.ts | Prompt security envelope and routing order |
| src/…/tools.ts | Tool risk model, whitelist boundary, and execution gate |
| src/…/sandbox.ts | Filesystem containment and session lifecycle boundary |
| src/index.ts | CLI entry points that connect runtime, reports, remediation, evidence, and watch services |
| src/…/index.ts | Public report and score outputs used by human and automated consumers |
| src/…/index.ts | Portable result bundle, verification, inspection, and fleet routing |
| src/…/watcher.ts | Baseline creation, change response, rescanning, and alert dispatch |
| src/…/score.ts | Security score and finding summary used by reports and drift checks |