Sandboxing Agent Tool Execution

RoadmapsAI Engineering

Overview

OS-level enforcement of filesystem and network isolation around agent tool execution.

Once an agent can execute code or shell commands, least-privilege prompting alone is not a security boundary. Containers alone are often incomplete without network and filesystem restrictions.

Where used: Production agent platforms, Sandboxed execution environments, Code-interpreter features

Why learn this

Code walkthrough

# ❌ NAIVE SETUP: High exfiltration risk
naive_sandbox = {
    "filesystem": {
        "allowWrite": ["/home/user/"]
    },
    "network": {
        "allowedDomains": ["*.github.com"]
    }
}

# ✅ SECURE SETUP: Independently scoped axes
secure_sandbox = {
    "filesystem": {
        "allowWrite": ["/app/workspace/build"]
    },
    "network": {
        "allowedDomains": ["registry.npmjs.org"]
    }
}

Focus: Each axis must be scoped independently. The naive setup allows broad write access to the home directory and network access to any GitHub domain, creating an exfiltration path via gists. The secure setup scopes filesystem writes exclusively to the build directory and network access solely to the required package registry.

Common mistakes

Recall questions

Understanding checks

What is the critical exfiltration risk in this sandbox configuration?

The sandbox allows read access to '/etc/secrets' and allows outbound network traffic to 'github.com'. A compromised agent could read the secrets and POST them to a public GitHub Gist.

Network isolation and filesystem isolation must be securely scoped together. Even trusted domains like github.com can be used as data exfiltration vectors if the agent has access to sensitive files.

A developer places their agent's Python code execution tool inside a standard Docker container and considers it securely sandboxed from data exfiltration. Are they correct?

No. A standard Docker container has default bridge networking, which allows outbound internet access.

Containers isolate processes, but without explicit network restrictions (like disabling egress) and strict filesystem boundaries, they are incomplete sandboxes.

Practice tasks

Scope a Secure Sandbox

Write a JSON configuration for a sandbox that only allows reading from '/project/src', writing to '/project/out', and strictly prevents all outbound network access by emptying the allowed domains.

Continue learning

Previous: Sandboxing and Least Privilege for Agents

Return to AI Engineering Roadmap