Skip to content
AgenticAIWiki
  1. Learn
  2. Part 12
  3. 65. Agent security
  4. 65.6

Lesson 65.6 · 6 of 10 · 4 min read · Reviewed 24 Nov 2026

Sandboxing code and browsers

By the end, you can

  • Sandbox agents that run code or browse.
  • Choose isolation for files, network and processes.

Running code and driving a browser are powerful, and both execute things you didn’t write.

What a sandbox limits

Resource Limit
Filesystem Only a working directory; no home directory, no secrets
Network None, or an allow-list of domains
Processes No root; resource limits on CPU, memory and time
Lifetime Fresh per task, destroyed afterwards

Options

  • Containers or micro-VMs for code executionCode execution tool: A built-in tool that lets the model run code in a sandbox and use the results. and computer useComputer use: Letting a model operate a computer through screenshots, mouse and keyboard actions..
  • Managed sandboxes, such as Claude’s code execution tool, which runs on Anthropic’s infrastructure.
  • OS-level sandboxingSandbox: An isolated environment that limits what code or an agent can reach, such as files, network or credentials. in Claude CodeClaude Code: Anthropic’s agentic coding tool that works in your terminal, IDE and CI, reading and editing code and running commands., which can restrict file and network access for the commands it runs.
  • In the browser, a sandboxed iframe with a strict content security policy. This site’s Playground runs your code that way, with no network access.

Remember

A sandbox limits damage; it doesn’t make a fooled agent behave. Combine it with least privilegeLeast privilege: Giving each component only the access it needs for its task, and no more. and approvals.

Key points

  • Agents that run code or control a browser need a sandbox: an isolated place with limited access.
  • Limit the filesystem, block or allow-list the network, and drop extra privileges.
  • Throw the sandbox away after each task so nothing persists between users.
Hands-on labOn your own machine

Run agent code in a locked-down container

Run untrusted, agent-written code in a throwaway container with no network, a read-only filesystem and resource limits.

You will have: A docker run command you can reuse, plus a short table of four escape attempts and what stopped each one.

Steps

  1. Install Docker following its official docs and pull a small Python image.
  2. Write a script with four probes: read ~/.ssh, open a network connection, write outside /work, and use a lot of memory.
  3. Run it with docker run --rm --network none --read-only --tmpfs /work --memory 256m --cpus 1 --user 1000:1000 and the script mounted read-only.
  4. Record which probe failed and why; then run it again without --network none and note the difference.
  5. Delete the container after each run (--rm does this) so nothing persists between tasks.

Done when

  • All four probes fail inside the locked-down container.
  • Your table names the flag that stopped each probe.

Docs: docker container run (Docker docs) · Sandboxing (Claude Code docs)

Quick checkAn agent runs user-provided Python to analyse data. What's the most important control?
How sure are you?
Pick an answer and how sure you are