2025-12-17 · Authensor

Sub-Millisecond Policy Evaluation: How SafeClaw Achieves Zero-Overhead AI Agent Security

Security that introduces latency gets disabled. This is not a theoretical concern -- it is an observed pattern across every domain where security tools compete with performance requirements. Developers disable slow linters. Operations teams bypass slow approval workflows. And engineers will disable an AI agent security layer that adds noticeable delay to every action.

SafeClaw evaluates policies in sub-millisecond time. An AI agent performing file writes, shell commands, or network requests experiences no perceptible overhead from SafeClaw's action-level gating. The security layer is, from the agent's perspective, invisible.

This article explains the architecture that makes sub-millisecond evaluation possible: local execution, pre-compiled patterns, early termination, allocation-free hot paths, and the deliberate absence of runtime dependencies.

Why Latency Matters for AI Agent Security

An AI agent performing a complex task might execute hundreds or thousands of individual actions. A coding agent working through a feature implementation might read dozens of files, write several, execute shell commands for testing and version control, and make network requests for documentation or API calls.

If each action incurs even 10 milliseconds of security evaluation overhead, a task with 500 actions accumulates 5 seconds of pure overhead. At 100 milliseconds per evaluation (typical for a network round trip to an external policy service), that task accumulates 50 seconds of overhead. This is not just annoying -- it fundamentally changes the agent's behavior. Agents with token budgets or time limits will accomplish less. Agents in interactive contexts will feel sluggish.

The performance requirement for AI agent security is clear: the evaluation must be fast enough that it disappears into the noise of normal operation. For SafeClaw, the target is sub-millisecond -- under 1,000 microseconds per evaluation. In practice, evaluations typically complete in 50-200 microseconds.

Architecture Overview

SafeClaw's policy evaluation happens entirely locally. There is no network involved in the decision path. The architecture looks like this:

Agent Action
    |
    v
[Action Interception Layer]
    |
    v
[Action Descriptor Construction]  -- ~microseconds
    |
    v
[Policy Engine Evaluation]        -- ~50-200 microseconds
    |
    v
[Audit Trail Entry]               -- ~microseconds
    |
    v
Allow / Deny

Every component in this path runs in the same process. The action descriptor is an in-memory object. The policy rules are in-memory data structures. The evaluation result is a boolean and a matched rule reference. There is no serialization, no deserialization, no network I/O, no disk I/O in the decision path.

Local Execution: Eliminating Network Latency

Many policy evaluation systems follow a client-server model: the client sends the action to a remote policy server, the server evaluates the policy, and returns the decision. This model has advantages (centralized policy management, consistent policy across clients) but introduces network latency that dominates the evaluation time.

A network round trip on a local network takes 0.5-2 milliseconds. On a cloud network, 1-10 milliseconds. On the public internet, 10-200 milliseconds. Even on localhost (loopback), the overhead of TCP connection management and serialization/deserialization is measurable.

SafeClaw eliminates this entirely. The policy engine runs in the SafeClaw client process. Policies are loaded at startup and cached in memory. When an action needs evaluation, the engine reads the action descriptor and the policy rules from local memory. No network call is made.

Policy updates from the Authensor control plane are handled asynchronously. When a policy is updated through the dashboard at safeclaw.onrender.com, the update is pushed to the client, which loads the new policy into memory. The update does not block ongoing evaluations -- the current evaluation completes with the current policy, and subsequent evaluations use the updated policy.

Pre-Compiled Patterns: Amortizing Regex Cost

Policy rules contain patterns for matching actions. A rule might specify that file_write actions to /workspace/* are allowed, or that shell_exec commands matching git are permitted. These patterns use glob syntax, which must be converted to regular expressions for matching.

Glob-to-regex conversion is not expensive for a single operation, but it is unnecessary to repeat it on every evaluation. SafeClaw compiles all glob patterns to regular expressions once, when the policy is loaded. The compiled regexes are cached alongside the rules in memory.

During evaluation, the engine calls regex.test(actionParameter) against pre-compiled regex objects. In V8 (the JavaScript engine in Node.js), compiled regex matching against short strings (file paths, commands, URLs) takes single-digit microseconds.

Policy load time (once):
  "/workspace/*"  -->  compile  -->  /^\/workspace\/.$/
  "git "          -->  compile  -->  /^git\s.$/
  "https://api.github.com/"  -->  compile  -->  /^https:\/\/api\.github\.com\/.$/

Evaluation time (per action):
/^\/workspace\/.*$/.test("/workspace/output.txt") --> true (~1-3 microseconds)

This amortization means that policy complexity (number of patterns, pattern length) affects load time but has minimal impact on per-evaluation latency.

First-Match-Wins: Early Termination

SafeClaw uses a first-match-wins evaluation model. Rules are evaluated in order, and the first rule that matches determines the decision. No further rules are evaluated.

This is a performance feature as much as a semantic one. For well-structured policies where common actions match early rules, the engine evaluates only a fraction of the total ruleset for most actions.

Consider a policy with 50 rules where the first 5 rules cover 90% of actions:

Rule 1: file_write to /workspace/** -> allow     (matches 40% of actions)
Rule 2: file_read from /workspace/** -> allow     (matches 30% of actions)
Rule 3: shell_exec "git *" -> allow               (matches 15% of actions)
Rule 4: network to api.github.com -> allow        (matches 5% of actions)
Rule 5: shell_exec "npm test" -> allow            (matches 2% of actions)
...
Rule 50: [default deny]                           (matches 8% of actions)

For 90% of actions, the engine evaluates at most 5 rules. For the remaining 10%, it evaluates more, up to the full 50. The average number of rules evaluated is far below the total, and the worst case (reaching the default deny) is bounded by the policy size.

This is why rule ordering matters for performance, not just correctness. Placing the most frequently matched rules first minimizes average evaluation time.

Allocation-Free Hot Path

Object allocation in JavaScript (and Node.js) is fast, but garbage collection is not free. Allocating objects in a hot path increases GC pressure, which can cause periodic pauses. In a system evaluating thousands of actions per second, this accumulates.

SafeClaw's evaluation hot path is designed to minimize allocations:

The evaluation function is essentially a for loop over an array, performing regex tests and returning early. There are no closures created during evaluation, no promises, no callbacks. The execution path is synchronous and linear.

Zero Dependencies: No Framework Overhead

SafeClaw has zero runtime dependencies. The policy engine does not use a rule engine library, an expression evaluation library, or a pattern matching framework. Every line of code in the evaluation path was written by the Authensor team, specifically for this use case.

This matters for performance because:

The 446 tests in the test suite include performance-related assertions. The evaluation path is tested not just for correctness but for adherence to the design constraints that enable sub-millisecond performance.

Benchmarking Methodology

Measuring sub-millisecond operations requires care. Standard JavaScript timing (Date.now()) has millisecond resolution and is insufficient. SafeClaw's benchmarks use process.hrtime.bigint() for nanosecond-resolution timing.

A representative benchmark:

Setup:
  - Policy with 20 rules covering file_write, shell_exec, and network actions
  - 10,000 action evaluations with a mix of action types
  - Actions designed to match at various points in the ruleset

Results (representative, varies by hardware):
- Mean evaluation time: 87 microseconds
- P50: 72 microseconds
- P95: 145 microseconds
- P99: 210 microseconds
- Max: 340 microseconds

All measurements are well below 1 millisecond. The P99 at 210 microseconds means that 99% of evaluations complete in about one-fifth of a millisecond. Even the worst case (340 microseconds) is one-third of a millisecond.

What Happens Under Load

When an agent performs many actions in rapid succession, the policy engine handles each evaluation independently. There is no queuing, no batching, no connection pooling. Each evaluation is a synchronous function call that returns immediately.

The single-threaded nature of Node.js means evaluations are serialized, but at sub-millisecond per evaluation, the throughput is enormous. At 100 microseconds per evaluation, the engine can handle 10,000 evaluations per second on a single thread. No real-world AI agent approaches this rate.

If the agent is performing I/O-bound operations (file reads, network requests), the policy evaluation completes during the same event loop tick as the action interception. The agent does not experience a separate "waiting for policy" phase.

Comparison to Remote Policy Evaluation

For context, here is how SafeClaw's local evaluation compares to a hypothetical remote policy service:

| Metric | SafeClaw (Local) | Remote Policy Service |
|---|---|---|
| Mean latency | ~100 microseconds | ~5-50 milliseconds |
| P99 latency | ~200 microseconds | ~100-500 milliseconds |
| Network dependency | None | Required |
| Failure mode | Local (process-level) | Network + service |
| Throughput | 10,000+ eval/sec | Limited by network |
| Offline operation | Full capability | Fails (or fails open) |

The difference is two to three orders of magnitude. For a single action, the difference might be imperceptible. For hundreds of actions in an agent task, it is the difference between invisible overhead and a noticeably slower agent.

The Performance-Security Tradeoff That Is Not

The conventional wisdom is that security introduces overhead. Firewalls add latency. Encryption adds CPU cost. Access controls add round trips. This is true in general, but it is not inherent. The overhead comes from specific architectural choices (network calls, disk I/O, complex computations), not from the concept of security itself.

SafeClaw demonstrates that AI agent security does not require a performance tradeoff. By evaluating locally, pre-compiling patterns, terminating early, avoiding allocations, and eliminating dependencies, the evaluation path achieves performance that is indistinguishable from no security at all -- from the agent's perspective.

The agent does not know SafeClaw is there. It should not. Security that is invisible is security that stays enabled.

Get started with npx @authensor/safeclaw. The free tier includes 7-day renewable keys. The browser dashboard is available at safeclaw.onrender.com. For more on the Authensor framework, visit authensor.com.

Try SafeClaw

Action-level gating for AI agents. Set it up in your browser in 60 seconds.

$ npx @authensor/safeclaw