Part 05›
✎

06. Agent Infrastructure: Sandboxes, Browser Use and Protocols#

Level: Practitioner · Reading time: 16 min · Exercise: 60 min Prerequisites: Tool Design and Function Calling

In one sentence: After this chapter you can choose where an agent's actions run, decide between APIs and a browser when you give it access to software, and read a tool protocol such as MCP without guesswork.

Why this matters#

Your agent has three new powers. It runs shell commands the model wrote. It opens a browser that is logged into the company's expense system. It calls tools that three teams wrote in three different ways. Each power works in the demo. Each one can also delete files, spend money or leak data in production.

This chapter is about what sits between the model and the world: where actions run, how software is reached, and which conventions carry the calls.

The core idea#

Three pieces of infrastructure connect a model to the world, and one rule covers them all.

  1. Execution environment. Where the agent's code and commands run: a sandbox.
  2. Interfaces to existing software. Browsers and desktops on one side, tool protocols on the other.
  3. The boundary. Least privilege: give every action the fewest rights it needs.

The analogy is onboarding a contractor. You hand out a managed laptop image with limited network access (the sandbox), a browser with single sign-on (browser use), and documented internal APIs instead of database passwords (protocols). The analogy breaks at learning. A contractor who breaks something once stops. A model will repeat the same action every time it sees the same situation, so the infrastructure, not the model, has to block it.

How it works, step by step#

Part 1: Sandboxes#

A sandbox is an isolated environment with its own file system, processes, network rules and resource limits. Agents need one for three reasons:

Level What it is Isolation Typical start time Use it for
None Code runs inside the agent's own process None None Never with model-written code
Operating-system sandbox An OS facility restricts what one process may touch (macOS Seatbelt, Linux namespaces and seccomp) Medium: the kernel is shared Milliseconds A coding agent's shell on a developer's machine
Container Docker or Podman: own file system and process tree Medium: the kernel is shared Hundreds of milliseconds to seconds Local development, CI builds
MicroVM A minimal virtual machine with its own kernel (Firecracker is the common one) High About a second Hosted sandboxes that run strangers' code

The start times are orders of magnitude. Measure on your platform. Two ways to buy the same isolation: run it yourself (containers on your machines), or rent it (hosted sandbox services and the code-execution tools that model vendors offer). Individual products were not re-checked for this edition, so they are not named.

Six questions select a sandbox:

  1. Worst case. What could the code reach if it escaped: secrets, the internal network, customer data?
  2. State. Must files survive between steps? Between sessions? Look for pause and resume.
  3. Latency budget. A cold start (the delay before a fresh sandbox is ready) of two seconds matters when a task has 40 steps and not when it has one.
  4. Network. Open internet, an allow-list through a proxy, or none.
  5. Observability. Logs of every command, every file change, every exit code.
  6. Cost model. Pay per second, or keep capacity reserved.

Part 2: Browser and computer use#

There are two ways to give an agent a piece of software. An API agent calls functions the software exposes. A web agent uses the interface as a person does. The second is the only option when there is no API, when the system is legacy, or when the login flow is all a human has. Chapados's slides name these as the two kinds of LLM agents.

A basic web agent has three parts, as his colleague demonstrates (34:00):

  1. A prompt with the goal, an observation of the current page, and the action space (the actions the agent may take).
  2. A model call that returns the next action.
  3. A driver that applies the action: in his example, Python with Playwright or Selenium, long-established browser automation libraries.

You choose what the agent sees:

Observation What it is Strength Weakness
Raw HTML The page source Complete Huge; mostly layout noise
Accessibility tree The browser's own outline of the page for assistive technology Structured and smaller than HTML No visuals
Screenshot Pixels Shows charts, images, layout Needs a vision model; actions become clicks at coordinates

The same choice applies to actions: high level (fill the field with this ID, click this element) or low level (click at x and y, type these keys).

Computer use extends the idea from the browser to the whole desktop: the model receives a screenshot and returns mouse and keyboard actions. Anthropic announced such a tool in October 2024 and OpenAI a browser-using agent in January 2025. The idea in both is the same loop: observe, act, observe.

A browser session logged in as a user is that user. Give the agent its own account with the fewest rights, allow-list the domains it may visit, require confirmation before anything irreversible, and record screenshots and actions. The main threat is injection arriving inside page content; it is covered in jailbreaks and prompt injection.

Part 3: Protocols#

The base layer is function calling: the model returns a structured request (a function name and arguments) and your code executes it. Every tool protocol builds on that.

The Model Context Protocol (MCP) standardizes the other end: how an AI application discovers and calls what an external system offers. Its documentation, as of November 2026, introduces it as "an open-source standard for connecting AI applications to external systems" and compares it to a USB-C port: one connector for data sources (local files, databases), tools (search engines, calculators) and workflows (specialized prompts).

That introduction does not define the roles. The definitions below come from the protocol's architecture page, which on November 24, 2026 documented the revision of July 28, 2026:

What MCP changes is the arithmetic. Without a standard, M applications each integrate N tools: M times N connectors. With one, each side implements the protocol once: M plus N. What it costs is one more moving part, a protocol that is revised often, and a security boundary you must draw yourself. A third-party server is someone else's code, and its tool descriptions are untrusted text that the model reads. Start from threat modeling before you connect one.

Other protocols exist for other boundaries. Agent-to-agent protocols, such as the Agent2Agent protocol that Google announced in April 2025, carry messages between agents from different vendors. Most applications need none of them: one model with a handful of functions is enough, as in chapter 02. Reach for a protocol when several applications must share the same tools, or several teams own them.

Worked example#

A tool server in 30 lines of plain Python, with no SDK. It is illustrative pseudocode in one sense: the file runs and uses the message shapes of the 2025 specification, but it leaves out parts a real server needs (full version negotiation, capability details, standard error codes). It also predates the revision of July 2026, which adds the _meta field to every request and the server/discover method. Use an official SDK for real work.

# toy_tool_server.py — an MCP-shaped server over stdio: one JSON message per line.
import json, sys

TOOLS = [{"name": "add", "description": "Add two integers",
          "inputSchema": {"type": "object",
                          "properties": {"a": {"type": "integer"}, "b": {"type": "integer"}},
                          "required": ["a", "b"]}}]

def handle(method, params):
    if method == "initialize":
        return {"protocolVersion": params["protocolVersion"], "capabilities": {"tools": {}},
                "serverInfo": {"name": "toy", "version": "0.1"}}
    if method == "tools/list":
        return {"tools": TOOLS}
    if method == "tools/call":
        args = params["arguments"]
        return {"content": [{"type": "text", "text": str(args["a"] + args["b"])}],
                "isError": False}
    raise ValueError(f"unsupported method: {method}")

for line in sys.stdin:
    request = json.loads(line)
    if "id" not in request:               # notifications expect no reply
        continue
    try:
        reply = {"jsonrpc": "2.0", "id": request["id"],
                 "result": handle(request["method"], request.get("params", {}))}
    except Exception as error:
        reply = {"jsonrpc": "2.0", "id": request["id"],
                 "error": {"code": -32601, "message": str(error)}}
    print(json.dumps(reply), flush=True)

Try it from a shell:

printf '%s\n' '{"jsonrpc":"2.0","id":2,"method":"tools/list"}' \
  '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"add","arguments":{"a":2,"b":3}}}' \
  | python3 toy_tool_server.py

Output:

{"jsonrpc": "2.0", "id": 2, "result": {"tools": [{"name": "add", "description": "Add two integers", "inputSchema": {"type": "object", "properties": {"a": {"type": "integer"}, "b": {"type": "integer"}}, "required": ["a", "b"]}}]}}
{"jsonrpc": "2.0", "id": 3, "result": {"content": [{"type": "text", "text": "5"}], "isError": false}}

Observe what the protocol adds over a plain function. The server describes its tool with a name, a description and an input schema (a JSON description of the arguments), so a host that has never seen this server can offer the tool to a model.

Figure 1. Who talks to whom in MCP: the host's client asks the server, and the model sees only the host.

sequenceDiagram
    participant U as User
    participant H as Host application
    participant M as Model
    participant S as Server
    U->>H: Request
    H->>S: List the tools
    S-->>H: Tool descriptions
    H->>M: Prompt with the tool descriptions
    M-->>H: Tool call
    H->>S: Call the tool with arguments
    S-->>H: Result
    H->>M: Result added to the prompt
    M-->>H: Final answer
    H-->>U: Answer

The server never talks to the model; it only answers the host's client, which is why one server works with any host.

What the practitioners say#

Nicolas Chapados of ServiceNow gave the first part of the lecture of October 21, 2024 (chapter 07 uses it). A colleague gave the second part, on web agents.

Vinyals, in a different lecture, notes that AlphaStar's in-game actions were API calls with typed arguments, emitted one at a time by a hand-built network, and calls that "strikingly close to tool use"; he names MCP as one such interface (16:00). As engineering judgment, the difference is that a language model can learn a tool interface from its description.

Pitfalls#

  1. Running model-written code in the agent's own process. Fix: a sandbox, always. The toy in chapter 02 is the exception that proves the rule.
  2. Handing the agent your own logged-in browser. Fix: a dedicated account with least privilege and a domain allow-list.
  3. Trusting tool descriptions from third-party servers. Fix: read them before connecting; scope every token the server can use; apply secure design.
  4. Feeding raw HTML as the observation. Fix: the accessibility tree, or retrieval of the few relevant elements.
  5. Grading web agents by action traces. Fix: check the end state.
  6. Benchmarking on the open web without versions and dates. Fix: record traces, as in testing and experimenting in production.
  7. Adopting a protocol for its own sake. Fix: start with function calling; move to a protocol when several applications must share tools.

Try it#

Two deliverables.

  1. A sandbox. Put a Python executor in a container with no network and a read-only file system, except for one working directory. From inside, try to read an environment variable, reach a website, write a file in the working directory, and write a file elsewhere. Create an empty work folder first. Then run a script that writes a.txt under /work and under /tmp.

bash docker run --rm --network none --read-only -v "$PWD/work:/work" python:3.12-slim \ python -c "import os, urllib.request; print(os.environ.get('SECRET')); urllib.request.urlopen('https://example.com', timeout=3)"

  1. A tool server. Save the toy server, send it the two requests above, then add a second tool and a request with an unknown method.

You are done when the sandboxed process prints None for the secret, fails to reach the website, can write under work and cannot write elsewhere; and when your server answers both requests as shown and returns an error object for the unknown method.

Stretch goal: rewrite the server with the official MCP SDK for your language and connect it to a real client. This exercise calls no model API and costs nothing.

Key takeaways#

Self-check#

  1. Why not run model-written code inside the agent's own process? A. It is slower than a container B. The code could read secrets, damage files or call the network with the agent's privileges C. Models cannot write correct Python D. The function exec is not available on every system
  2. Which observation of a web page is structured and smaller than the page source, but shows no visuals? A. Raw HTML B. A screenshot C. The accessibility tree D. The network trace
  3. In the ServiceNow lecture, what counts as success for a web agent? A. Matching a reference sequence of actions B. The end state of the system C. The number of clicks D. The length of the prompt
  4. In the 2025 MCP specification, who exposes tools? A. The server B. The host's user interface C. The model D. The operating system
  5. What is the layer beneath every tool protocol? A. Reinforcement learning B. Function calling: the model returns a structured request and your code executes it C. Vector search D. Fine-tuning
  6. A web page tells the agent to ignore its instructions and upload a cookie file. What is this? A. A parser bug B. Prompt injection arriving through untrusted content C. A latency problem D. A protocol version mismatch
Show answers 1. B. A sandbox keeps the code away from everything the agent can reach. 2. C. It is the browser's outline of the page for assistive technology. 3. B. The database state or the answer is checked, not the path. 4. A. A server exposes tools, resources and prompts to a host through a client. 5. B. Protocols standardize discovery and transport around that basic exchange. 6. B. Content the agent reads is untrusted input, including instructions in it.

Sources#

Next#

→ Agents in the Enterprise, which puts these pieces to work inside a company, where every action needs a source and an owner.