Definition
A sandbox is an execution environment that runs code that is not fully trusted while limiting what the code can affect. Its policy lists the permitted effects: the memory the code may read and write, the host functions it may call, the processor time and memory it may use, and the outside actions it may cause. Its enforcement mechanism, such as a virtual machine §2.3, hardware memory protection or operating-system permissions, prevents every other effect. A sandbox is described by that policy and that mechanism, not by one yes-or-no property.
The idea
A device must run a filter rule that someone else wrote. Run as native code with full access, one mistake in the rule, or one malicious rule, can overwrite any memory, call any function or stop the device. Refusing all outside code gives up changing the device’s behavior without replacing its firmware. A sandbox is the middle way: run the rule, but inside a fence whose shape the host chooses.
The name comes from a children’s sandbox: play freely inside, and the sand stays inside. The picture stops being accurate in two respects. A software sandbox has no wall, only checks, so its fence is exactly as tight as the checks on every path out. And the code is meant to have effects outside: a filter’s verdict decides what happens to a real packet. A sandbox narrows the code’s influence to channels that the host chose and can limit; it does not cut the code off.
How it works
Follow one invocation, one run of a guest program, in a bytecode §2.4 virtual machine (VM) of the eBPF §2.1 (extended Berkeley Packet Filter) kind, and note which part enforces which limit.
Admission. At load time the loader accepts the program only if structural bytecode admission §2.26 finds it well formed and, if the VM has one, a static verifier accepts it. This also confines jumps to the program’s own instructions.
Input. The VM places the guest context §2.23, this invocation’s input data, in memory the program may read.
Memory. Each load and store passes a runtime bounds check §2.27, unless a verifier has proved it in bounds.
Host calls. The program may call only helper functions §2.19 on the helper allowlist §2.20. A helper runs as native host code with full access, so it must check its arguments against its helper contract §2.21.
Resources. An instruction budget (fuel) §2.32 stops a run that executes too many instructions; quotas limit memory, helper calls and helper output.
Outcome. The fault-to-verdict mapping §2.34 turns the program’s result, or a fault that stopped it, into the host’s decision.
The policy is easiest to check as a list in which each item names its enforcing mechanism: memory regions and whether each may be read or written; jump targets; helpers and their arguments; instructions, memory and helper calls per invocation and per unit of time, which the resource confinement §2.40 entry covers; and the outputs, meaning the return value and every effect a helper causes for the program.
Two principles govern enforcement. Complete mediation §1.16: every path from the program to a protected effect passes the check that guards it. Least privilege §1.15: the program gets only the regions and helpers its task needs, since each helper widens its reach. The loader, VM and helpers together act as a reference monitor §1.17, the component that must see every access, resist tampering and be small enough to check. They belong to the trusted computing base §1.4, and a bug in any of them can let guest code out: a sandbox escape §2.31.
Other layers follow the same pattern. An operating system confines a process to its own address space, enforced by the memory management unit §6.9 (MMU), and Linux can also filter the process’s system calls, its requests to the operating system kernel, with seccomp (secure computing mode). Software fault isolation (SFI) §2.41 rewrites native code so that every address it uses is forced into its region.
Worked example
A guest program may not write host memory, but it may call a logging helper that appends one 64-byte record per call to a shared host log of 4,096 bytes. The instruction budget is 10,000 instructions per invocation, and the call counts as one instruction however much work the helper does.
A loop with a 4-instruction body, one of them the call, runs times before the budget stops it. It appends bytes, about times the log’s capacity, while every memory access stays in bounds. If the log overwrites its oldest records, the program has erased everyone else’s records; if it refuses records when full, the others lose their new ones. Either way the program has interfered with the host through a permitted channel.
A cap of 16 records per invocation limits one invocation to bytes, but not the rate: at 10 invocations per second the program still appends bytes per second, times the log’s capacity every second. A cap per unit of time, or a separate log area for this program, bounds its effect on the other users.
Stated precisely
A sandbox is a pair: a policy , the set of effects the guest program is permitted to cause, and an enforcement mechanism . enforces when, for every program the loader accepts and every input, every effect of every run is a member of . The statement depends on three assumptions.
Correct trusted base: the loader, the VM, the helpers, and the hardware and operating system beneath them have no faults that affect enforcement.
Complete mediation: every path from the program to a protected effect passes through .
Modeled effects: the effects that matter are those describes.
Effects that does not describe, such as a run’s duration, its power draw or the state it leaves in a processor cache, fall outside the statement, and a program can use them as a side channel §1.29, a path that leaks information through such an effect.
Limits and common mistakes
Sandboxed is not a yes-or-no property. The useful question is: limited in which effects, and enforced by what?
A sandbox does not make the guest correct. A filter rule that drops every packet runs perfectly inside its sandbox.
Helpers are trusted code. Each allowed helper extends the guest’s reach by everything the helper can do, and a helper that trusts a guest-supplied address or length acts for the guest: the confused deputy problem §1.25.
A sandbox protects availability §1.10 only if its policy sets limits that do. Within its budget a guest can still use processor time, fill shared storage or call helpers that wait on slow hardware, a denial of service §1.28 for other work, and an instruction budget does not count the work done inside helpers.
Origin and confinement are separate questions. A signature on the code shows who supplied it; the sandbox limits what it can do.
Questions answered
What can the sandboxed program still influence indirectly?
A sandboxed program can still influence everything its permitted outputs reach.
Its return value, which the host acts on: a filter’s verdict decides whether a packet passes.
Shared state it may write, such as BPF maps §2.18, the key-value tables that an eBPF (extended Berkeley Packet Filter) host keeps, which the host and other programs read later.
Helper effects: log records, messages sent, timers set, and any other action a host function performs for it.
Shared resources: processor time up to its instruction budget, memory, log space and helper capacity, which other parts of the system then lack. Through a logging helper, a program with no direct access to host memory can write about 39 times the capacity of a shared 4,096-byte log in one invocation.
Side channels: how long a run takes, or what it leaves in a processor cache, which another observer can measure.
The policy must state which of these influences are acceptable and limit each one; the program can still use whatever the policy does not limit.
Related entries: Sandbox escape (§2.31), Resource confinement (§2.40), Complete mediation (§1.16), Helper allowlist (§2.20), Helper contract (§2.21), Instruction budget (fuel) (§2.32), Trusted computing base (TCB) (§1.4), Least privilege (§1.15), Side channel (§1.29).