Review the prerequisites
Suitable for: Backend developers learning Agent applications.
- Isolate resources and capabilities when executing code
- Code execution risk depends on the capabilities the process actually possesses. Restrictions must be enforced by the execution environment over files, networks, credentials, process trees, and resources, and conventions in the prompt are not a substitute for isolation.
How does the mechanism work?
Step-by-step explanation
- What are the risks of mounting a Docker socket?
Access to control sockets can expand a container's capabilities, so describe those capabilities explicitly.
- What should I do if the main process exits after the code opens a background subprocess?
Execution lifetime limits need to cover the entire process tree.
- Can restricting only file paths prevent symlinks from going out of bounds?
File access restrictions must account for path resolution and race conditions.
Debugging · Diagnose failures
Public repair exercise: same inputs
Objectives of this level: manifest capability and three independent resource bounds — Locate the supplied fault and repair a copy on unchanged input.
Visual guide · Admission is before enforcement
The local function plans admission only. An executor must enforce mounts, network, credentials, process-tree lifetime and limits; a prompt cannot enforce them. Select the figure to open it at full size.
Public repair exercise: same inputs
Use cpu-over and host-socket first. The supplied faulty function returns allow for both, so the first divergence is admission before any execution. Repair by separating shape validation, current identity, capability subset and each numeric bound. Preserve at-all-limits and zero-output as positive controls. Changing the expected result or shrinking the request is not a repair. This is guided_repair: the faulty category is supplied. Save the function below in a separate coding_sandbox_boundary_debug.py. Before consulting a repair, submit the first divergent input/field, two hypotheses and a discriminating check. Repair this copy, save your diff and rerun the identical cases; keep the original cases file unchanged.
def sandbox_plan(payload):
# Known fault: no authority/capability/resource checks.
return {"decision": "allow", "reason": "bounded_manifest"}
python3 lab_runner.py grade --course coding-sandbox-boundary --module coding_sandbox_boundary_debug.py --out coding_sandbox_boundary_debug_before.json
python3 lab_runner.py grade --course coding-sandbox-boundary --module coding_sandbox_boundary_debug.py --out coding_sandbox_boundary_debug_after.json
Starting point and evidence
Download the source-only ZIP, extract it, and work in extended-agent-practice-v1 with lab_runner.py beside cases/. Python3.9+ standard library; no model, cloud, network or business request is made. Scaffold once in a fresh directory; it refuses overwrite. Reuse your module in later tracks. The empty template must exit1 on grade; scaffold exits0, overwrite exits2. Grade exits0 only when every fixed case passes and otherwise exits1.
- https://ai.lwkjob.com/downloads/extended-agent-practice-v1.zip
- https://ai.lwkjob.com/lab/extended-practice/lab_runner.py
- https://ai.lwkjob.com/lab/extended-practice/cases/coding-sandbox-boundary.json
python3 lab_runner.py scaffold --course coding-sandbox-boundary --out coding_sandbox_boundary_student.py
python3 lab_runner.py grade --course coding-sandbox-boundary --module coding_sandbox_boundary_student.py --out coding_sandbox_boundary_before.json
This course has10 public fixed cases. Each calls your sandbox_plan(payload), records input/expected/actual/error, strict JSON types, input immutability and no output-container aliases, plus module/runner/cases SHA and Python version. Inputs are complete JSON fixtures. Unknown or missing keys, null outside explicitly allowed fields, wrong types, duplicate IDs/list members where uniqueness is required raise ValueError:input_shape; booleans are not integers. Exceptions match exact class:message. Return fresh JSON values without mutating input.
Trusted identity, approvals, receipts and policy/index metadata are fixtures assembled by the exercise. In a real service the server must obtain them from authenticated/current authority sources; accepting client JSON with these labels does not authenticate it. The function is a decision over that trusted snapshot, not the adapter or race-proof enforcement.
Local function contract
payload has exactly principal/request/policy. principal={tenant:nonempty str,enabled:strict bool}. request={tenant:nonempty str,capabilities:unique nonempty str list,cpu_ms:positive strict int,memory_mb:positive strict int,artifact_bytes:nonnegative strict int}. policy={capabilities:unique nonempty str list,max_cpu_ms:positive strict int,max_memory_mb:positive strict int,max_artifact_bytes:nonnegative strict int}. Empty capability lists are legal. Validate all nested shapes first. Then deny in this order: tenant_mismatch, principal_disabled, capability (requested set is not a subset), cpu_budget, memory_budget, artifact_budget. Equality with a maximum is allowed. Return exactly decision and reason: deny plus the first reason, or allow/bounded_manifest. No execution or cleanup occurs.
def sandbox_plan(payload):
raise NotImplementedError("Implement the public local contract")
Three reviewable inputs
at-all-limits
{
"principal": {
"tenant": "acme",
"enabled": true
},
"request": {
"tenant": "acme",
"capabilities": [
"read_csv",
"write_chart"
],
"cpu_ms": 100,
"memory_mb": 64,
"artifact_bytes": 1000
},
"policy": {
"capabilities": [
"read_csv",
"write_chart"
],
"max_cpu_ms": 100,
"max_memory_mb": 64,
"max_artifact_bytes": 1000
}
}
Expected / 预期: {"decision": "allow", "reason": "bounded_manifest"}
cpu-over
{
"principal": {
"tenant": "acme",
"enabled": true
},
"request": {
"tenant": "acme",
"capabilities": [
"read_csv",
"write_chart"
],
"cpu_ms": 101,
"memory_mb": 64,
"artifact_bytes": 1000
},
"policy": {
"capabilities": [
"read_csv",
"write_chart"
],
"max_cpu_ms": 100,
"max_memory_mb": 64,
"max_artifact_bytes": 1000
}
}
Expected / 预期: {"decision": "deny", "reason": "cpu_budget"}
host-socket
{
"principal": {
"tenant": "acme",
"enabled": true
},
"request": {
"tenant": "acme",
"capabilities": [
"host_socket"
],
"cpu_ms": 100,
"memory_mb": 64,
"artifact_bytes": 1000
},
"policy": {
"capabilities": [
"read_csv",
"write_chart"
],
"max_cpu_ms": 100,
"max_memory_mb": 64,
"max_artifact_bytes": 1000
}
}
Expected / 预期: {"decision": "deny", "reason": "capability"}
Responsibility and limits
Junior delivers a strict manifest decision and boundary tests. Intermediate connects a proposed admission adapter to the chart stage with observable rejection and per-task cleanup ownership. Senior compares process/container/VM boundaries and specifies host control-plane isolation, resource reservations and artifact failure windows. Only the pure decision is implemented here; actual OS isolation remains unverified. The four tracks are learning activities, not job ranks. Fixed authored examples and known repairs cannot prove independent diagnosis, real-world security or hiring readiness. Keep source, initial failure, personal diff, same-input rerun and a declared changed-condition result. A reviewer-new complete contract and observed personal work are separate; disclose assistance. The five-second worker guard is not a performance SLO or hostile-code sandbox.
code example
Public repair exercise: same inputs — host-socket
Additional review: explain why this case follows the contract and which single-field change would alter the branch. Public case: host-socket Expected / 预期: {"decision": "deny", "reason": "capability"} https://ai.lwkjob.com/lab/extended-practice/cases/coding-sandbox-boundary.json
Acceptance task for this level
manifest capability and three independent resource bounds — Run the supplied faulty copy, record a first divergence and two hypotheses, then repair it with a personal diff and the unchanged-case rerun.
Reading this browser’s record…
Hide the answer and check your understanding
What observation identifies the first bug?
Expand reference derivation
cpu-over is accepted before any executor exists; inspect the admission branch rather than blaming a timeout.
Further explanations and practice
When encountering unfamiliar principles, first read the implementation, continuous questioning and migration cases, and then independently explain the premise and boundaries. Answers and notes are saved to the original account record.
All linked explanations and exercises (1 )
Sources and verification scope
The principles are based on public information; the numbers, cases and tasks are the teaching design of this website. Offline experiments verify the range noted on this page, and the learning effect still needs to be judged through independent tasks and feedback.
- OWASP:LLM prompt injection prevention
- MCP:Security best practices
- Docker: daemon, mounting and isolation risks
- Docker: container CPU and memory constraints
- Linux openat2: path resolution limitations
- Extended practice runner and source ZIP
- Pure-function public contract
- Actual learner-module grader
- Executable Harness integration