Chapter 4 · Practice 5 of 5
Run model-written code in an isolated sandbox
Why it matters
If your agent executes code, assume that code is hostile. It was written by a model that may have read an attacker's instructions.
Run it in a sandbox with:
- no access to your secrets
- a read-only or throwaway filesystem
- CPU, memory and time limits
- network access turned off, or limited to an allowlist
Never run model-generated code in the same process or container as your app server.
Test the sandbox by asking the agent to:
- read environment variables,
- reach an internal host,
- write outside its directory.
All three should fail.