autogen icon indicating copy to clipboard operation
autogen copied to clipboard

Proposal: Standardized Safety Sandbox for Agent Tool Execution

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

As multi-agent frameworks evolve, tool execution becomes a critical security vector.

Problem: Currently, many agents execute code or tools with broad permissions. While sandboxing exists (Docker, etc.), there isn't a standardized, portable way to define safety constraints per tool or per agent that is framework-agnostic.

Proposal: Introduce a ToolSafetyPolicy interface that can be implemented by different executors (Docker, Firecracker, WASM).

  • Allow defining allow_network, allow_filesystem, max_memory, etc. at the tool definition level.
  • Ensure these policies are enforced by the executor before the tool runs.

This would align Autogen with emerging safety standards in AI.

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

Safety sandboxes for agent tool execution is critical for production deployments. At RevolutionAI (https://revolutionai.io), we've implemented multi-layer sandboxing:

Our sandbox architecture:

┌─────────────────────────────────────┐
│  Agent Decision Layer               │
├─────────────────────────────────────┤
│  Permission Gate (allowlist check)  │
├─────────────────────────────────────┤
│  Resource Limiter (CPU/mem/time)    │
├─────────────────────────────────────┤
│  Isolation Container (gVisor/Firecracker)
├─────────────────────────────────────┤
│  Audit Logger (immutable trail)     │
└─────────────────────────────────────┘

Key components we use:

  1. Static analysis — Parse tool calls before execution, reject suspicious patterns
  2. Resource quotas — Hard limits on memory (512MB), CPU (1 core), time (30s)
  3. Network isolation — Tools can't make arbitrary network calls
  4. Filesystem isolation — Virtualized FS, no access to host
  5. Capability-based permissions — Tools request specific capabilities, granted per-task

Implementation options:

  • gVisor — Google's container sandbox, great security/performance tradeoff
  • Firecracker — AWS microVMs, strongest isolation but more overhead
  • nsjail — Lightweight, good for simple tool execution

Would love to see this standardized in AutoGen. Happy to share our implementation details or contribute to an RFC!

xXMrNidaXx avatar Feb 23 '26 13:02 xXMrNidaXx

Strong proposal. The ToolSafetyPolicy interface idea is particularly compelling because it separates policy definition from enforcement mechanism — you can define constraints once and have them enforced whether the executor is Docker, Firecracker, or WASM.

A few dimensions worth considering in the interface design:

Per-invocation vs per-tool policies. Static tool-level policies (allow_network=false) cover the common case, but agents operating on untrusted input may need dynamic policy adjustment. For example, a web-scraping tool might be safe by default but should have tighter constraints when processing content from an untrusted source. The policy interface could support a context parameter that lets the orchestrator tighten constraints based on input provenance.

Content-level security complements execution sandboxing. Sandboxing prevents a compromised tool from escaping its boundaries, but it doesn't prevent the agent from being instructed to misuse a tool within its allowed permissions. Indirect prompt injection through retrieved documents or tool outputs can steer the agent to make dangerous-but-technically-permitted calls. Scanning tool inputs and outputs for injection patterns (something like ClawMoat does for agent content) adds a layer that pure execution sandboxing misses.

Audit logging should be a first-class concern. Every policy evaluation (pass or fail) should produce a structured event. This is critical for both incident response and for tuning policies over time.

Would the ToolSafetyPolicy be enforced at the AutoGen runtime level, or would it be delegated to individual executor implementations? The former gives stronger guarantees but requires runtime changes; the latter is more flexible but risks inconsistent enforcement.

darfaz avatar Feb 25 '26 08:02 darfaz

+1 on standardized safety sandboxes! Critical for production agents.

Key patterns we use:

import subprocess
import tempfile
import os

class SafeSandbox:
    def __init__(self, allowed_commands: list[str]):
        self.allowed = set(allowed_commands)
        
    def execute(self, cmd: str, timeout: int = 30):
        # Allowlist check
        base_cmd = cmd.split()[0]
        if base_cmd not in self.allowed:
            raise SecurityError(f"Command {base_cmd} not allowed")
            
        # Isolated temp directory
        with tempfile.TemporaryDirectory() as tmpdir:
            result = subprocess.run(
                cmd,
                shell=True,
                cwd=tmpdir,
                timeout=timeout,
                capture_output=True,
                env={"PATH": "/usr/bin", "HOME": tmpdir}
            )
            return result.stdout.decode()

For Docker isolation:

docker run --rm --network none --memory 256m --cpus 0.5 sandbox:latest

Would love to see this as a first-class AutoGen feature!


Building safe AI agents? https://www.revolutionai.io/find-work

xXMrNidaXx avatar Feb 25 '26 09:02 xXMrNidaXx

This is exactly the execution boundary we're interested in with Aegisora.

For us, the critical invariant is that a guardrail decision must remain bound to the exact agent, tool, arguments and approval context until the final tool dispatch - otherwise authorization can become advisory rather than enforced.

We're inviting independent reproductions: https://github.com/aegisora-ai/aegisora/issues/28

AEGISORA-W31-AUTOGEN

ozereray avatar Sep 10 '26 16:09 ozereray

Great to see the active discussion and inputs from @xXMrNidaXx, @darfaz, and @ozereray.

Looking at the contributions, there is strong consensus on three design requirements:

  1. Policy vs. Enforcement Separation: A clean ToolSafetyPolicy abstraction that doesn't tie AutoGen directly to Docker, gVisor, or Firecracker.
  2. Context-bound Invariants (highlighted by @ozereray): Authorization decisions must remain cryptographically or deterministically bound to (agent_id, tool_name, args, approval_context) until final dispatch.
  3. Structured Audit Events: Every policy check (allow/deny/quarantine) must emit an immutable log entry.

To move this forward, I propose a minimal, non-breaking MVP for AutoGen:

  • Introduce an abstract BaseToolGuard interface in the tool dispatch lifecycle (pre_execute / post_execute hooks).
  • Default to a PermissiveGuard (current behavior) while allowing pluggable external sandboxes (Docker/WASM/Firecracker).

I can put together an initial PR with this minimal hook interface and tests if the core maintainers are open to reviewing it. Thoughts?

Protocol-zero-0 avatar Sep 10 '26 19:09 Protocol-zero-0

Thanks — I think this is a sensible direction for AutoGen, especially keeping the policy abstraction independent from the sandbox implementation.

I strongly agree with the context-bound invariant. In particular, the authorization decision should not merely exist before dispatch; the exact security-relevant execution context it authorized — (agent_id, tool_name, args, approval_context) — needs to remain bound through the final dispatch boundary. Otherwise, a clean pre_execute hook can still authorize one action while a materially different action reaches the sandbox.

I also think the audit contract should distinguish at least decision, enforcement, and observed execution rather than treating them as one event. That makes it possible to represent cases such as “allowed but not observed to execute” without inference.

The proposed BaseToolGuard hooks seem like a reasonable minimal integration point. My only caution would be making the default behavior explicit: a PermissiveGuard can preserve backward compatibility, but it should not be interpreted as providing a safety guarantee. The guard/sandbox boundary should make that distinction visible in the contract and tests.

A small MVP covering context-binding, allow/deny enforcement, and immutable structured events would give maintainers a concrete surface to review without committing AutoGen to a particular sandbox technology.

Jim @.***>, 10 Eyl 2026 Per, 22:00 tarihinde şunu yazdı:

Protocol-zero-0 left a comment (microsoft/autogen#7230) https://github.com/microsoft/autogen/issues/7230#issuecomment-5624655049

Great to see the active discussion and inputs from Corey nida @.) https://github.com/xXMrNidaXx, Dar @.) https://github.com/darfaz, and Eray Özer @.***) https://github.com/ozereray.

Looking at the contributions, there is strong consensus on three design requirements:

  1. Policy vs. Enforcement Separation: A clean ToolSafetyPolicy abstraction that doesn't tie AutoGen directly to Docker, gVisor, or Firecracker.
  2. Context-bound Invariants (highlighted by Eray Özer @.***) https://github.com/ozereray): Authorization decisions must remain cryptographically or deterministically bound to (agent_id, tool_name, args, approval_context) until final dispatch.
  3. Structured Audit Events: Every policy check (allow/deny/quarantine) must emit an immutable log entry.

To move this forward, I propose a minimal, non-breaking MVP for AutoGen:

  • Introduce an abstract BaseToolGuard interface in the tool dispatch lifecycle (pre_execute / post_execute hooks).
  • Default to a PermissiveGuard (current behavior) while allowing pluggable external sandboxes (Docker/WASM/Firecracker).

I can put together an initial PR with this minimal hook interface and tests if the core maintainers are open to reviewing it. Thoughts?

— Reply to this email directly, view it on GitHub https://github.com/microsoft/autogen/issues/7230?email_source=notifications&email_token=A4KE3NQUOBJ7K2QZZR5GSSL5OMB4ZA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNRSGQ3DKNJQGQ42M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-5624655049, or unsubscribe https://github.com/notifications/unsubscribe-auth/A4KE3NT72M7FGC6LZQEPGWT5OMB4ZAVCNFSNUABFKJSXA33TNF2G64TZHM3DQMBRGIYDANZRHNEXG43VMU5TGOJTGYYDCMJWGU3KC5QC . You are receiving this because you were mentioned.Message ID: <microsoft/autogen/issues/7230/5624655049 @.***>

ozereray avatar Sep 10 '26 22:09 ozereray

Thanks @ozereray — this sharpens the MVP in a useful way. I agree that the review surface should be defined by testable invariants before choosing the implementation hooks.

I would narrow the initial contract to four points:

  1. Exact context binding. A decision is bound to the security-relevant execution context — at minimum (agent_id, tool_name, validated_args, approval_context) plus a stable call/decision identity. The same context must reach final dispatch; mutation, substitution, or invalid replay must be rejected before any side effect.
  2. Enforcement at dispatch. ALLOW permits the bound call, while DENY produces zero tool invocations. An approved call whose tool, arguments, agent, or approval context changes must also produce zero invocations.
  3. Evidence without inference. Policy decision, enforcement at the dispatch boundary, and observed execution/outcome should be separate structured records linked by stable identifiers. An ALLOW record alone must not be interpreted as proof that execution occurred.
  4. Explicit compatibility semantics. A PermissiveGuard may preserve current behavior, but its public contract and tests should state that it provides no safety guarantee.

A minimal, sandbox-neutral test matrix could use an inert counting tool:

  • exact bound ALLOW dispatches once;
  • DENY dispatches zero times;
  • post-decision rebinding of tool, args, agent, or approval context is rejected with zero dispatches;
  • replay is rejected where decisions are single-use;
  • cancellation after a decision but before dispatch records no observed execution;
  • streaming and non-streaming tool paths cross the same enforcement boundary.

Before I prepare a PR, I would like maintainer guidance on placement. AutoGen is now in maintenance mode and its contribution guidance limits new feature work. Would this narrowly scoped interface plus invariant tests be reviewable here as security hardening, or should the work target an extension layer or Microsoft Agent Framework instead? The backend-neutral sandbox discussion in microsoft/agent-framework#7568 looks related, although the contract above concerns authorization continuity and execution evidence rather than sandbox provisioning alone.

@ozereray, if you have a small existing fixture for the binding boundary, its expected behavior would be useful for comparing the contract without coupling the implementation to Aegisora.

Protocol-zero-0 avatar Sep 12 '26 05:09 Protocol-zero-0

Strong +1 to @ozereray's point on exact context binding ((agent_id, tool_name, validated_args, approval_context)) and separating policy decisions from observed execution evidence.

We implemented and stress-tested this exact contract in ASL (Agent Safety Layer) using a <3,000 LOC stdlib-only trusted core (2,998 lines, 97.7% AST mutation kill rate across 599 mutants):

  1. Exact Context Binding & Single-Use Nonces: Every capability token is HMAC-SHA256 signed over canonical JSON (parse_json_strict rejecting duplicate keys/NaN) binding (agent_id, run_id, action, args_hash, issued_at, expires_at, nonce). Any post-mint argument mutation, cross-agent token replay, or sub-agent scope widening (TokenAuthority.attenuate) fails closed before dispatch.
  2. Evidence Without Inference: Every dispatch writes to a hash-chained AuditChain and emits a compact X-ASL-Attestation wire token (<base64url(payload)>.<hex_hmac>) binding run_id, backend_class (verified via active probes B0–B4), policy_hash, and audit_head_hash.
  3. Reproducible Conformance Kit: Rather than tying callers to a single sandbox vendor, we published language-neutral JSON test vectors + a standalone 200-line stdlib verifier (python conformance/verify_vectors.py) alongside signed receipts for 250 public exploit payloads (250/250 breaching an undefended control stub, 0/250 breaching ASL):

Repo / Conformance Vectors: https://github.com/Raja549h/asl-conformance-kit

Happy to contribute the canonical JSON / token-binding vector format if helpful for the BaseToolGuard / ToolSafetyPolicy test matrix here.

Raja549h avatar Oct 27 '26 06:10 Raja549h