File System and Network Access Control
What you'll learn: How to restrict file system operations and network calls inside sandboxes to prevent AI-generated code from leaking data or accessing unauthorized resources.
The Core Problem
When your AI system generates and executes code in a sandbox (like a Docker container or serverless function), that code could attempt to read sensitive files, write malicious data, or make network requests to exfiltrate information. Even with process isolation, an attacker could craft prompts that trick the AI into generating code that steals API keys from /etc/secrets, uploads data to external servers, or scans your internal network.
How It Works
File system controls limit which directories generated code can read, write, or execute. You create a minimal filesystem view — perhaps only a /tmp/workspace folder — and make everything else invisible or read-only. Configuration files, credentials, and system directories stay completely off-limits.
Network access control blocks or restricts outbound connections. You might disable all network access entirely (air-gapped execution), whitelist only specific domains (like your own API endpoints), or route through a filtering proxy that logs and inspects all requests.
Implementation Patterns
Use your container's capabilities (Docker's --network=none flag), language-specific sandboxes with custom file/network handlers, or operating system tools like chroot, seccomp, and firewall rules. For serverless functions, configure VPCs and security groups to deny unexpected traffic.
Analogy: Think of it like giving someone a locked room with only a whiteboard and marker — they can't access the filing cabinets outside or make phone calls, even if they want to.
Key Takeaway: Always enforce strict file system boundaries and network restrictions in code execution sandboxes to prevent AI-generated code from reading secrets, modifying critical files, or exfiltrating data to external systems.