mech.app

The mech.app newsletter

Agentic AI, minus the noise.

Get practical field notes on AI agents, automation, developer tools and security delivered to your inbox.

No spam. Unsubscribe anytime.

Security

Enclawed Code: How Deterministic Security Layers Harden Claude Code Agent Execution

Deterministic security boundaries for Claude Code agents that enforce action-level constraints outside the LLM, replacing probabilistic guardrails.

Source: enclawed.com
Enclawed Code: How Deterministic Security Layers Harden Claude Code Agent Execution

Enclawed Code wraps Claude Code in a deterministic security layer that checks every action before execution. The core insight: stop asking the LLM to judge safety. Instead, enforce boundaries at the infrastructure layer using a fixed rule that asks one question: can this action be undone?

The project ships as open source with a companion research paper showing zero harmful actions passed and zero harmless actions blocked across 15,021 real tool calls. It also claims 7.7x fewer approval prompts than Claude Code’s default permission mode.

The Problem with Probabilistic Guardrails

Claude Code and similar agents execute shell commands, edit files, and call tools on your local machine. They read context along the way: README files, web pages, tool output. Anyone can plant instructions in those contexts.

Traditional safeguards rely on the LLM to recognize malicious intent. This creates three failure modes:

  • Prompt injection: Planted instructions can override safety directives
  • Context confusion: The model cannot reliably distinguish user intent from embedded commands
  • Permission fatigue: Too many prompts train users to approve without reading

Enclawed Code moves the security boundary outside the model. It intercepts every action before execution and applies a deterministic rule. The LLM never sees the security decision.

Architecture: Where the Boundary Sits

Enclawed Code runs as a wrapper around the standard Claude Code CLI. You type ecwcode instead of claude. The security layer sits between the agent’s action planner and the host system.

Execution Flow

  1. Session start: Security key unlock (hardware-backed if Enclaweder is present)
  2. Action interception: Every tool call, command, and file operation is caught before execution
  3. Reversibility check: Fixed rule evaluates whether the action can be undone
  4. Routing decision:
    • Reversible actions run immediately in a sealed space
    • Irreversible actions trigger a human approval prompt with a typed code
  5. State tracking: Old file versions are preserved, sealed execution spaces are isolated

The sealed space is a sandboxed environment where read operations, read-only commands, file edits (with automatic versioning), and tests execute without approval.

What Counts as Reversible

Action TypeReversible?Execution Path
File readYesRuns in sealed space
Read-only shell commandYesRuns in sealed space
File editYesRuns after old version saved
Test executionYesRuns in isolated environment
Network callNoRequires approval
System configuration changeNoRequires approval
Package installationNoRequires approval
Destructive file operationNoRequires approval

The reversibility rule is not configurable by the LLM. It is a fixed policy enforced at the infrastructure layer.

Security Boundary Enforcement

Enclawed Code uses three mechanisms to enforce boundaries:

1. Action Classification

Every tool call is parsed and classified before execution. The system extracts the operation type, target resources, and scope. This happens outside the LLM’s control.

# Conceptual flow (not actual Enclawed Code source)
def intercept_action(action):
    parsed = parse_tool_call(action)
    
    if is_reversible(parsed):
        old_state = snapshot_affected_resources(parsed)
        result = execute_in_sealed_space(action)
        log_action(action, old_state, result)
        return result
    else:
        approval_code = generate_approval_code()
        user_input = prompt_user(action, approval_code)
        if user_input == approval_code:
            result = execute_with_full_privileges(action)
            log_action(action, None, result)
            return result
        else:
            raise SecurityViolation("Action blocked by user")

2. Sealed Execution Spaces

Reversible actions run in isolated environments. File system changes are copy-on-write. Network access is restricted. The sealed space is torn down after execution, but state changes (like edited files) are committed back to the host with full audit trails.

3. Hardware Root of Trust (Optional)

When paired with Enclaweder, the security key unlock uses hardware-backed attestation. This prevents a compromised host from bypassing the approval flow. The research paper reports 11 attacks from compromised computers, all blocked with Enclaweder present.

Benchmark Results

The companion paper (DOI: 10.5281/zenodo.24524917) tested three Claude models across four permission modes with 4,350 live runs. Key findings:

  • Planted attack blocking: 93 attacks embedded in context (README files, tool output, web pages) were run against live Claude models. Enclawed Code blocked all 93.
  • False positive rate: Zero harmless actions were stopped across 15,021 tool calls.
  • Approval fatigue reduction: 7.7x fewer prompts than Claude Code’s default mode, because reversible actions run without interruption.
  • Compromised host resilience: 11 attacks from a compromised computer (modified system libraries, tampered binaries) were blocked when Enclaweder hardware attestation was enabled.

The benchmark does not test performance overhead. The paper focuses on security effectiveness, not latency.

Deployment Considerations

Where It Fits

Enclawed Code is a local wrapper. It does not require cloud infrastructure or API changes. You install it on the same machine where you run Claude Code.

This makes it suitable for:

  • Local development workflows where engineers use Claude Code for refactoring, test generation, or debugging
  • Regulated environments where every action must be auditable and reversible
  • Red team exercises where you want to test agent behavior under adversarial conditions

It is not suitable for:

  • Fully autonomous agents that run unattended (the approval flow requires human input for irreversible actions)
  • High-throughput batch processing (the security checks add latency to every action)
  • Cloud-hosted agents (the current implementation is local-only)

State Management

Enclawed Code preserves session state across security violations. If an action is blocked, the agent’s conversation history, file snapshots, and sealed space state remain intact. The user can resume the session after reviewing the blocked action.

This is critical for long-running sessions where a single blocked action should not discard hours of work.

Observability Gaps

The current implementation logs every action, approval decision, and state snapshot. However, it does not expose metrics for:

  • Latency per action type (how much overhead does the security layer add?)
  • Approval prompt response time (how long do users take to review irreversible actions?)
  • Sealed space resource usage (memory, disk, CPU for isolated execution)

These gaps make it hard to predict performance impact in production.

Failure Modes

1. Reversibility Misclassification

The fixed rule might incorrectly classify an action as reversible. For example, a file edit that triggers a build process with side effects (like uploading artifacts) would run without approval.

Mitigation: The sealed space restricts network access, so most side effects are contained. But this is not foolproof.

2. Approval Fatigue (Still Possible)

If the agent generates many irreversible actions, users still face approval prompts. The 7.7x reduction helps, but it does not eliminate the problem.

Mitigation: Tune the agent’s system prompt to prefer reversible operations. This is a prompt engineering task, not a security fix.

3. Hardware Dependency for Full Protection

Without Enclaweder, a compromised host can bypass the security layer. The approval prompt is just a UI element. An attacker with root access can modify the binary to skip checks.

Mitigation: Deploy Enclaweder for hardware-backed attestation. This adds cost and complexity.

Technical Verdict

Use Enclawed Code when:

  • You run Claude Code locally and need audit trails for every action
  • You work in regulated environments where reversibility is a compliance requirement
  • You want to test agent behavior under adversarial conditions (planted instructions, compromised hosts)
  • You can tolerate latency overhead for security checks

Avoid it when:

  • You need fully autonomous agents that run unattended (the approval flow breaks autonomy)
  • You deploy agents in cloud environments (the current implementation is local-only)
  • You require sub-second action latency (the security layer adds overhead, though the paper does not quantify it)
  • You cannot deploy hardware attestation but face sophisticated attackers (software-only protection is bypassable)

The core idea is sound: move security decisions outside the LLM. The implementation is production-ready for local workflows but needs cloud deployment support and better observability before it scales to multi-tenant or high-throughput scenarios.