liveBook · Manning

Sandboxing

As explained in Designing AI Agents

A sandbox is an isolated execution environment that restricts a system's access to resources and external effects.

Sandboxing confines an agent’s execution to defined resource boundaries, such as writable paths and network destinations. Clear limits can let routine actions proceed without repeated approval; one evaluation reported an 84% reduction in permission prompts. Isolation limits technical reach, not business correctness. section 9.1.2 section 9.3.3

Separate the controls that determine what an agent can reach from those that determine when it must stop:

  • Filesystem policy can allow writes in configured paths while blocking changes elsewhere; read access may follow a separate policy. section 9.3.3
  • Network isolation can route outbound connections through a proxy that restricts destinations and requests approval for new ones. section 9.3.3
  • Choose an isolation boundary according to the threat model and escape impact, weighing startup, memory, compatibility, and lifecycle costs. section 9.3.3
Table 9.5 Isolation mechanisms and operational trade-offs
Mechanism
Isolation boundary
Startup/footprint evidence
Operational trade-off
Typical fit
Docker/runc
Shared host kernel
Fast process-level startup
Low overhead; host kernel remains shared
Trusted workloads with host hardening
gVisor
User-space application kernel
Adds a system-call mediation path
Compatibility and I/O cost require workload testing
Untrusted containers needing user-space syscall mediation
Firecracker microVM
Dedicated guest kernel
Design goals: <125 ms startup; <5 MiB VMM [11]
Separate guest kernel with VM image and lifecycle management
Workloads requiring a dedicated guest kernel
bubblewrap/Seatbelt
OS-level process sandbox
Process-level startup
Platform-specific policy surface; not a VM boundary
Local coding agents
WebAssembly
Language/runtime sandbox
Fast module instantiation
Host capabilities must be explicitly exposed
Plugins and portable functions

Compare shared-kernel containers, user-space kernels, microVMs, OS-level sandboxes, and WebAssembly by boundary and operational trade-off. section 9.3.3

Keep policy checks distinct from physical isolation. A configuration can declare allowed tools, paths, network destinations, rate limits, costs, and resource limits; predicates validate individual limits, and an executor composes the checks before calling a supplied runtime. The adapter—not the policy wrapper—must enforce actual isolation and runtime limits. section 9.3.5

Listing 9.7 Layered execution gauntlet (patterns/blast_radius.py)
    def execute(
        self, tool_name: str, args: dict,
        estimated_cost: float = 0.01,
        execute_fn=None,
    ) -> dict:
        """Check the envelope, then invoke the supplied runtime."""
        if (
            self.config.allowed_tools
            and tool_name not in self.config.allowed_tools
        ):
            return {"error": f"Tool '{tool_name}' not in allowlist"}
 
        path_keys = ("path", "file_path", "cwd", "repo", "repo_root")
        for key in path_keys:                        #A
            if key in args and not self.validate_path(args[key]):
                return {"error": f"{key} outside policy boundary"}
 
        if not self.check_rate_limit():
            return {"error": "Rate limit exceeded"}
        if not self.check_budget(estimated_cost):
            return {"error": "Budget exceeded"}
 
        if self.config.time_lock_seconds > 0:        #B
            time.sleep(self.config.time_lock_seconds)
 
        self.action_timestamps.append(time.time())
        self.cumulative_cost += estimated_cost
        if execute_fn:
            return execute_fn(tool_name, args)       #C
        return {"status": "checked", "tool": tool_name, "args": args}

Inspect the layered execution example, which checks tool access, paths, rate limits, and budget before invoking the supplied function. section 9.3.5

How Designing AI Agents covers it

How deep it goes
Compares isolation boundaries and implements policy checks, but delegates physical isolation and some resource enforcement to a runtime adapter.
Examples
Uses Claude Code, Codex, E2B, Manus, and a Python executor with path, rate, cost, and runtime limits as examples.
What you can do after
Configure a policy envelope and compose checks before invoking a runtime that enforces actual isolation.
How it connects
Connects sandboxing with approval policies, threat models, filesystem controls, network isolation, and runtime adapters.

Also explained in

Compare how 10 books explain sandboxing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Designing AI Agents. The section links point to the parts of the book it draws on.