Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:AI Shell Team Aish Sandbox Pre Run

From Leeroopedia
Knowledge Sources
Domains Security, Sandboxing
Last Updated 2026-10-29 00:00 GMT

Overview

Pattern for trial-running an AI-generated command in an overlay filesystem sandbox to observe filesystem changes before deciding whether to allow execution.

Description

Sandbox Pre-Run is the mechanism that executes a command in an isolated overlay filesystem to observe what it would do, without affecting the real filesystem. The analyze_with_sandbox method sends the command to a sandbox daemon via IPC, which runs it in an overlay filesystem mounted on top of the working directory. The sandbox captures all filesystem changes (creates, modifies, deletes), the exit code, and any errors.

The assess_sandbox_result function evaluates the sandbox result: if no changes occurred, the default risk level is used; if changes occurred, they are evaluated against policy rules (e.g., writing to `/etc` is high risk); if the exit code is non-zero, medium risk is assigned (require confirmation).

This pattern solves the problem of determining what a command will do without actually executing it on the real system, giving the security pipeline concrete evidence for its decision.

Usage

Use this principle when a security pipeline needs to observe command behavior before allowing execution. The sandbox should be optional (configurable in the policy), and the result assessment should map observed changes to risk levels.

Theoretical Basis

The pre-run is a trial-execute-then-assess pipeline:

# Abstract algorithm (NOT real implementation)
def analyze_with_sandbox(command, request):
    result = sandbox.run(command, request.cwd, request.repo_root, request.timeout)
    return assess_sandbox_result(policy, command, result)

def assess_sandbox_result(policy, command, sandbox):
    changes = convert_changes(sandbox.changes)

    if sandbox.changes.is_empty():
        return Analysis(risk=policy.default_risk, reason="no filesystem changes")

    if sandbox.exit_code != 0:
        return Analysis(risk=Medium, reason="non-zero exit code")

    # Evaluate changes against policy rules
    for change in changes:
        rule = match_rule(change.command_name, change.path)
        if rule and rule.risk > current_risk:
            current_risk = rule.risk

    return Analysis(risk=current_risk, changes=changes)

Key design ideas:

  • Overlay filesystem isolation: the command runs in a copy-on-write overlay, so real files are not modified
  • Change-based assessment: the risk level is determined by what the command changed, not just its name
  • Exit code awareness: a non-zero exit code triggers confirmation even without policy matches
  • Default risk fallback: no changes → default risk level from policy

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment