learn-claude-code icon indicating copy to clipboard operation
learn-claude-code copied to clipboard

[Proposal] v5_secure_agent: Implementing Sandboxing & Command Middleware

Open Protocol-zero-0 opened this issue 9 months ago • 3 comments

The current learning path brilliantly demonstrates capability scaling from v0 (Bash) to v4 (Skills). However, the v0 "Bash is all you need" paradigm, while powerful for personal use, presents significant risks for autonomous deployment.

Proposal: v5_secure_agent.py

I suggest adding a v5 module focused on Agent Security & Containment, implementing the "Trust but Verify" pattern:

  1. Command Middleware: A simple interceptor for the bash tool that checks commands against an allowlist/denylist (e.g., blocking rm -rf / or recursive deletions without explicit confirmation flags).
  2. Read-Only Mode: A toggle to disable write/edit tools or restrict them to a specific workspace directory (jail).
  3. Human-in-the-Loop (HITL): A pattern for escalating high-risk actions (network requests, large file deletions) to the user for confirmation.

This would round out the curriculum by addressing the primary barrier to productionizing these agents: Safety.

Protocol-zero-0 avatar Feb 13 '26 16:02 Protocol-zero-0

This is a natural next step for the learning path. Security is the gap between "cool demo" and "something you can actually deploy."

A few implementation notes that might save time:

Command middleware is the most impactful piece. Intercepting tool calls before execution and checking them against policy rules gives you the biggest safety improvement for the least code. The middleware pattern works because it is framework-agnostic: you wrap the tool execution function, evaluate the request, and either pass it through or block it. No changes to existing tools needed.

The allowlist/denylist split matters less than the default. Deny-by-default (block everything not explicitly allowed) is safer than allow-by-default with a denylist (allow everything not explicitly blocked). The denylist approach means every novel attack vector you did not anticipate gets through. Deny-by-default means it gets blocked, and you open up what the agent actually needs.

Credential files need hardcoded protection. Regardless of the user's policy config, block access to .env, .aws/credentials, *.pem, and similar patterns by default. This is the single most common real-world agent incident. An agent that reads your .env during a "help me debug" session just put your production API keys into a context window that gets logged, stored, and potentially sent to third-party servers.

Audit logging rounds it out. Every allow/deny decision should be recorded with the action, the rule that matched, and a timestamp. Without this, debugging why the agent got blocked is frustrating and compliance is impossible.

For reference, SafeClaw implements all of this as a standalone policy engine: YAML-defined rules, tri-state decisions (allow/deny/require-approval), deny-by-default, sub-millisecond evaluation, and tamper-proof audit trails. It could serve as a reference implementation for the v5 module, or you could integrate it directly since it wraps any tool-calling agent.

The HITL pattern you described maps to the "require-approval" state in a tri-state model. Safe operations get auto-approved. Dangerous operations get hard-blocked. Everything in between pauses for human confirmation. This keeps the developer experience smooth while catching destructive actions.

AUTHENSOR avatar Feb 13 '26 19:02 AUTHENSOR

Solid points on the middleware pattern and deny-by-default. The 'tri-state' (allow/deny/ask) model is definitely the sweet spot for DX vs Security. I'll review SafeClaw's implementation for reference. Appreciate the detailed breakdown. ⚡

Protocol-zero-0 avatar Feb 22 '26 07:02 Protocol-zero-0

Thanks for the thoughtful proposal and the follow-up discussion.

Security is an important topic, but it doesn't fit the current s01-s12 architecture. Each session adds one agent mechanism (loop, tools, planning, compression, tasks, teams, etc.). Security/sandboxing is an orthogonal concern -- it applies across all sessions rather than being a progressive step in the agent capability chain.

The project scope is intentionally narrow: teach how agent internals work, not how to harden them for production. These are complementary but different goals.

Closing as out-of-scope for the current architecture. The middleware pattern discussed here is solid engineering -- just not the right fit for this project's structure.

安全是重要话题,但不符合当前 s01-s12 的架构设计。每个 session 加一个 agent 机制,安全是横切关注点而非渐进能力。项目聚焦于"agent 怎么工作",而非"怎么加固"。

CrazyBoyM avatar Feb 27 '26 07:02 CrazyBoyM