Introducing a new way to review your PRs.

Read the announcement

affaan-m / agentshield

AI agent security scanner. Detect vulnerabilities in agent configurations, MCP servers, and tool permissions. Available as CLI, GitHub Action, ECC plugin, and GitHub App integration. 🛡️

View on GitHub

20 documents · Updated Sep 11, 2026

docs / runtime-and-operations

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:

ControlPurposeOperational result
Deny rulesStop a tool or matching inputThe call is blocked with a reason
LoggingRecord the decision and timingAn append-only NDJSON trail supports review
Policy validityConfirm the policy can be usedStatus 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 formMain use
Terminal, Markdown, or HTML reportHuman review and status sharing
JSON reportScripts and service integrations
SARIF reportCode-scanning and CI systems
Evidence packPortable audit and security-review handoff
Remediation plan or fix summaryWork assignment and change review
Baseline drift and watch alertOngoing 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:

  1. The initial scan establishes the accepted view of the target.
  2. A file change triggers a debounced scan.
  3. The new result is compared with the baseline.
  4. Drift is exposed to operators through the selected alert path.
  5. 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

TriggerConsequenceGuard
The runtime hook is missingActive tool calls do not pass through AgentShield enforcementRun runtime status checks and install the hook before relying on runtime protection
Settings or runtime policy JSON is invalidThe monitor is not ready, and installation stops rather than modifying a broken settings fileUse runtime repair; it backs up invalid files before rebuilding the monitor
A policy file is missing or cannot be loadedStatus reports a problem, while the policy loader falls back to its default allow-all policyTreat ready status as a deployment condition and inspect policy validity before use
A requested path traverses the sandbox or reaches a symlink outside itThe filesystem operation is rejected and the session cannot use that pathResolve and validate the path before access, including a real-path check for existing targets
A session creates a disallowed or oversized fileThe file operation is blocked or the resource limit is reachedApply extension and size checks before the operation
A MiniClaw session exceeds its duration or its sandbox cleanup failsThe request can expire, or orphaned session files can remainEnforce session time limits and inspect cleanup or server-stop results
A client exceeds request or IP limitsThe service rejects the request before prompt work beginsUse the health endpoint for liveness and tune limits for the expected client load
A report or evidence artifact is changed or missingReviewers may use incomplete or untrusted security resultsVerify the evidence pack before inspection or fleet routing
A watched target changes and introduces new findingsThe baseline no longer describes the current security postureReview the drift alert and fix, roll back, or explicitly accept the change

Key files

FileWhy to read it
src/…/index.tsPublic boundary for policy loading, evaluation, installation, repair, and status
src/…/install.tsRuntime monitor lifecycle and safe recovery behavior
src/…/status.tsReadiness states used by operators and checks
src/…/evaluator.tsTool-call decision and runtime log contract
src/…/index.tsPublic MiniClaw entry points for standalone and embedded use
src/…/server.tsSession, request, event, health, and shutdown service flow
src/…/router.tsPrompt security envelope and routing order
src/…/tools.tsTool risk model, whitelist boundary, and execution gate
src/…/sandbox.tsFilesystem containment and session lifecycle boundary
src/index.tsCLI entry points that connect runtime, reports, remediation, evidence, and watch services
src/…/index.tsPublic report and score outputs used by human and automated consumers
src/…/index.tsPortable result bundle, verification, inspection, and fleet routing
src/…/watcher.tsBaseline creation, change response, rescanning, and alert dispatch
src/…/score.tsSecurity score and finding summary used by reports and drift checks