Sandboxing and Permissions
About 40 min
Goal
By the end of this lesson, you can distinguish permission policy from process isolation and design layered limits for tool execution, files, network access, and resources.
Permission and containment are different
A permission check asks whether an action is allowed. A sandbox asks what the executing process can actually reach. These controls overlap, but they solve different problems. A policy might allow a code tool for one task while the sandbox still blocks access to the host file system, unrelated network endpoints, or excessive CPU and memory.
Imagine the controller allows run_analysis on a user-provided CSV file. That permission does not mean the analysis process should read SSH keys from the host or send data to any internet address. A sandbox can expose only the mounted input directory, provide no credentials, restrict networking, and limit resources.
Layering matters because software can fail. A tool adapter might contain a bug, generated code might do something unexpected, or a dependency might behave differently than expected. If permissions are the only control, a bug inside an allowed tool may still reach too much. Isolation reduces the damage available to that process.
policy: allow run_analysis on /workspace/task/report.txt
sandbox: process can reach /workspace/task only
request: /home/user/.ssh/id_rsa → blocked by containment
Layer trust and isolation
Zero trust is a security approach that avoids granting broad access merely because something is already inside a network or system. For an agent harness, the practical lesson is to verify each request against identity, task context, and policy, then give the execution environment only the resources required for that operation.
Containers are one common isolation boundary, but a container is not automatically a perfect sandbox. Configuration matters: mounted directories, capabilities, network mode, user privileges, secrets, and resource limits all change what the process can do. The useful learning target is least privilege, not the assumption that one technology name guarantees safety.
Resource limits are part of containment. A code tool that cannot read secrets may still consume all memory or run forever. Timeouts, CPU quotas, memory limits, process limits, and output limits help preserve system availability. These controls belong outside model instructions.
Keep scope narrow and auditable
Permissions should be narrow in both action and scope. 'Can write files' is much broader than 'can write one report file under this task directory.' 'Can access network' is broader than 'can call the inventory API endpoint needed for this task.' Scope reduces the consequences of mistakes.
Audit evidence should record the requested action, principal (the trusted user or service identity on whose behalf the action would occur), policy result, sandbox profile, and final outcome. This helps distinguish a denied request from an allowed request that failed inside the isolated environment.
Do not treat isolation as a reason to relax approval rules. A sandbox may limit technical reach, but a refund or deletion can still be harmful even when performed from a tightly restricted process. Authorization, approval, and sandboxing should reinforce one another.
Predict
Run the local Lab
Run:
python labs/notebooks/level-12/l12-05-sandbox-policy.py
The Lab evaluates requested file, network, and resource capabilities against a small sandbox profile.
- Run it unchanged and confirm path, network, and memory checks are all
True. - In
request, findPurePosixPath("/workspace/task/report.txt"). Before editing, predict which one of the three checks should change if only the path leaves the permitted task directory. - Change only that path to
PurePosixPath("/home/user/.ssh/id_rsa"), then rerun. - Confirm the path check becomes
Falsewhile network and memory remainTrue, and the final assertion blocks the request. Restore the starter afterward.
Loading lab…
Write the core logic yourself
Open:
labs/notebooks/level-12/l12-05-sandbox-policy-exercise.py
Implement path, network-host, and memory checks. The good request must pass while each single-boundary violation remains blocked.
Run:
python labs/notebooks/level-12/l12-05-sandbox-policy-exercise.py
A correct implementation reaches the PASS: marker. Try hints 1 and 2 before comparing with the completed exercise (labs/answers/advanced/level-12/l12-05-sandbox-policy-answer.py).
Stuck? Show hint 1
Each request must satisfy all three independent policy boundaries: destination path, host, and memory.
Python syntax stuck? See P9 — policy records.
Stuck? Show hint 2
Check path.is_relative_to(write_root), host in network_hosts, and memory_mb <= max_memory_mb; combine with and.
Hint 3 — completed TODO code
Try the earlier hints first. Compare only after attempting the exercise.
def allowed(request, profile=PROFILE):
path_ok = request["path"].is_relative_to(profile["write_root"])
host_ok = request["host"] in profile["network_hosts"]
memory_ok = request["memory_mb"] <= profile["max_memory_mb"]
return path_ok and host_ok and memory_ok
Quick Check
Explain it back
For a code-execution tool, describe one permission rule, one file-system restriction, one network restriction, and one resource limit. Explain why each belongs to a different control layer.
Check your explanation
A strong answer mentions:
- Authorization: allow code execution only for an approved principal/task; it controls who may invoke the tool.
- File isolation: restrict readable/writable paths; network isolation: deny or allowlist outbound access—these constrain what code can reach.
- Resource boundary: enforce CPU/memory/runtime budgets; sandbox configuration and resource limits are separate from human approval for high-impact actions.
Key Takeaways
- Authorization and isolation solve different problems.
- Least privilege narrows both action and scope.
- Container configuration determines the real boundary.
- Resource limits protect system availability.
- Sandboxing does not replace approval for high-impact actions.
Next Lesson
Next, L12.6 — Memory Retrieval and Compression examines how long-running agents keep useful context without silently losing important evidence.
References
- Open Container Initiative, Runtime Specification.
- NIST, SP 800-207 — Zero Trust Architecture.
Completion is stored locally on this device.