---
title: "Execution boundaries, isolation, and sandboxes"
id: "building-blocks/01-execution-boundaries-isolation-and-sandboxes"
summary: "Compare execution locations and isolation mechanisms, then describe their resources through an executor contract."
pass: "Pass 1: Building Blocks"
learning_path: "main"
status: "complete"
last_reviewed: "2026-10-10"
canonical_url: "https://renatomignone.github.io/From-LLMs-to-Secure-Agents/building-blocks/01-execution-boundaries-isolation-and-sandboxes/"
---

# Execution boundaries, isolation, and sandboxes

> **Summary:** Compare execution locations and isolation mechanisms, then describe their resources through an executor contract.
> **Section:** Building blocks · **Chapter:** 29 · **Path:** Main path · **Reviewed:** 2026-10-10

# Execution boundaries, isolation, and sandboxes

## Why this matters

An assistant needs to summarize a sales file. Its tool might call a trusted Python function inside the application, launch a separate program or send work to a hosted execution service. All three can return the same total, yet they expose different files, credentials and machine resources.

The [identity chapter](https://github.com/RenatoMignone/From-LLMs-to-Secure-Agents/blob/main/knowledge/03-building-blocks/08-identity-authorization-and-secrets/chapter-plan.md) explained who acts. This chapter asks where that software runs and which boundary separates it from other work.

## Simple mental model

Think of workshops sharing a building. Different workbenches, separate rooms and separate buildings create different boundaries. A remote address tells you where the workshop is, but not what tools it can use or which other customers share it.

A **host** is the machine or operating-system environment supporting execution. A **process** is a running program with its own execution state and address space. The **kernel** is the operating-system component managing processes, memory and access to devices. A **system call** requests a service from the kernel.

## How it works

### Start with what the job needs

Our sales job needs one input file, a parser, temporary memory and an output summary. It does not need a browser session or order credentials. Before choosing an environment, describe the required interfaces, resource limits, persistent state and output contract.

An **execution boundary** separates the job from other software or resources. **Isolation** limits what it can observe or affect across that boundary. A **sandbox** is a configured environment that restricts execution. The word alone does not specify the mechanism or the exposed resources.

### Compare mechanisms rather than labels

| Mechanism | Where the job runs | Main distinction to understand |
| --- | --- | --- |
| In-process function | Application process | Shares the application's process and available resources |
| Subprocess | Separate process | Has a separate address space; can still inherit files and credentials |
| Container | Isolated operating-system views | Typically shares the host kernel |
| Application kernel | Workload behind an implemented kernel interface | Interposes a separate software layer on system calls |
| Virtual machine | Guest operating system | Runs its own guest kernel with virtualized machine resources |

A **namespace** gives processes a particular view of operating-system resources. A **container** packages a workload with such views and associated runtime settings. Docker uses namespaces and **control groups**, or cgroups, which account for and limit resources. Shared directories and runtime configuration change the resulting exposure. [Docker Engine security](https://docs.docker.com/engine/security/).

An **image** packages the files and configuration used to create an environment. It is not the same as a running container: writable changes and runtime settings belong to the instance.

gVisor supplies an application kernel in userspace, outside the host kernel. It handles workload system calls through its own implementations, so compatibility depends on the supported interfaces. [gVisor architecture](https://gvisor.dev/docs/architecture_guide/intro/).

A **virtual machine**, or VM, runs a guest operating system through virtualization. A **hypervisor** manages its virtualized machine boundary. A **microVM** uses a smaller virtual-machine design. Firecracker uses Linux KVM virtualization with a guest kernel and a minimal device model. [Firecracker design](https://raw.githubusercontent.com/firecracker-microvm/firecracker/main/docs/design.md).

![Three robot workshops show a shared-kernel container, an application-kernel sandbox and a virtual machine with a guest kernel.](/From-LLMs-to-Secure-Agents/assets/images/03-building-blocks/09-execution-environments/01-execution-boundaries-isolation-and-sandboxes/01-concept.webp)

*Figure 1. Compare the execution layers beneath each workload. The different layers change the boundary, but each environment still exposes selected files and interfaces. These are alternatives, not three mandatory layers in every agent.*

### Location and mechanism are separate

A **remote worker** executes outside the calling application's local environment. It might itself use a container, VM or ordinary process. A **hosted sandbox** is an execution service managed by another operator. Inspect its resource and lifecycle contract rather than treating “hosted” as an isolation mechanism.

The caller sends a job request and receives a result or job identifier. Network delivery, scheduling and remote failure handling are additional concerns. The caller's timeout does not necessarily stop the remote worker.

### Identify who owns each part

A **harness** is the runtime that coordinates model turns, tools and execution limits. It may run in your application or in a managed service. An **environment** supplies execution resources, such as files, a shell or a browser. A managed harness can use a provider-hosted environment or connect to one you operate. Application tool handlers may still run in your own service.

| Part | Question to answer |
| --- | --- |
| Harness | Who schedules turns, records progress and applies runtime limits? |
| Environment | Who configures files, networks, processes and resource cleanup? |
| Application | Who validates business operations, credentials and external results? |

Record these responsibilities for the actual deployment. A service managing the loop does not automatically own every tool or external transaction. [Managed architecture](https://developers.openai.com/api/docs/guides/agents-api/architecture).

## Minimal implementation

The [offline executor interface](https://github.com/RenatoMignone/From-LLMs-to-Secure-Agents/blob/main/examples/03-building-blocks/09-execution-environments/01-execution-boundaries-isolation-and-sandboxes/main.py) accepts a named operation, input identifier and environment label. Its mock supports two labels with one result contract. The example verifies unsupported jobs and environment names and never runs model-generated code.

<details><summary>Expand minimal Python implementation</summary>

```python
class Executor(Protocol):
    def submit(self, job: Job) -> Result: ...
```

</details>

The interface lets orchestration reason about a job without knowing container or VM implementation details. The mock's labels demonstrate routing only. They do not create actual isolation or measure its strength.

## Limitations and trade-offs

Isolation choices affect startup time, compatibility, operating effort and resource use. A trusted stock lookup and a general code-execution job may require different designs. Measure the actual workload; do not infer a universal performance ranking from the comparison table.

An environment can be separated from the host while retaining access to mounted data or external services. Its authority also depends on the credentials supplied to it. The next chapter maps these resources and follows the environment through cleanup.

## Security preview

Pass 2 revisits escape, network and resource-abuse risks in [execution and supply-chain security](https://github.com/RenatoMignone/From-LLMs-to-Secure-Agents/blob/main/knowledge/07-security-by-component-and-workflow-stage/04-execution-and-supply-chain/chapter-plan.md). [Human oversight](https://github.com/RenatoMignone/From-LLMs-to-Secure-Agents/blob/main/knowledge/03-building-blocks/10-human-in-the-loop/chapter-plan.md) later explains decisions about execution. An approval decision and an isolation boundary have different jobs.

## Key takeaways

- State the job's required resources before choosing an environment.
- Processes, containers, application kernels and VMs create different boundaries.
- Remote execution describes location; its isolation mechanism needs a separate description.
- An executor contract can stay stable while the environment implementation changes.

<details><summary>Check your understanding</summary>

Is remote execution itself an isolation guarantee? No. Location and the configured execution boundary are separate choices.

</details>

## References

- Docker. [Docker Engine security](https://docs.docker.com/engine/security/).
- gVisor. [Introduction to gVisor security](https://gvisor.dev/docs/architecture_guide/intro/).
- Firecracker maintainers. [Firecracker design](https://raw.githubusercontent.com/firecracker-microvm/firecracker/main/docs/design.md). Living implementation documents, verified for this run.

- OpenAI. [Agents API architecture](https://developers.openai.com/api/docs/guides/agents-api/architecture). Living documentation, verified October 10, 2026.

---

[Next unit: Browsers, files, networks, resources, and cleanup →](/From-LLMs-to-Secure-Agents/building-blocks/02-browsers-files-networks-resources-and-cleanup/)

## Sources & Evidence
- [Docker Engine security](https://docs.docker.com/engine/security/) (Docker, null)
- [Introduction to gVisor security](https://gvisor.dev/docs/architecture_guide/intro/) (gVisor, null)
- [Firecracker design](https://raw.githubusercontent.com/firecracker-microvm/firecracker/main/docs/design.md) (Firecracker maintainers, null)
- [Agents API architecture](https://developers.openai.com/api/docs/guides/agents-api/architecture) (OpenAI, null)
