Free self-study · No account needed · Progress stays in this browser. Back it up before clearing site data or changing devices.

← Week 18: Sandboxing and Governance

Week 18 / Lesson 1

Enforcing process and resource restrictions

Demonstrate actual file, network, process, and resource boundaries.

Section 1.1 1 of 7

Overview

Focus

Demonstrate actual file, network, process, and resource boundaries.

Your route through the lesson

  • 1.2 Least privilege and required authority
  • 1.3 Container isolation and filesystem mounts
  • 1.4 Network egress and secret exposure
  • 1.5 Put it into practice
  • 1.6 Guided comparison
  • 1.7 A writable host mount in a worker container

All required teaching is included here. Review selections are saved. Choose a correct answer for every question to continue; retries are unlimited. Study time and personal notes are optional.

Section 1.2 2 of 7

Least privilege and required authority

Focus

Give a worker only the authority required for its declared task.

Least privilege means granting the minimum capabilities needed for supported work. Start from the task: this worker reads one synthetic input and writes scratch output. It does not need your home directory, project credentials, unrestricted networking, administrator identity, or permission to launch child processes. A model instruction describing those limits is not enforcement; the process must actually lack the capability.

Distinguish application policy from runtime restriction. A Python if statement can reject a represented export request, but arbitrary code in the same process may bypass that function and call the operating system directly. An enforced runtime boundary constrains those calls regardless of the model's explanation. The permitted action must succeed and a forbidden action must fail when actually attempted.

Resources are authority too. Memory, processor time, process count, and scratch storage need limits so one worker cannot exhaust the host. The core fixture prepares safe data, while a separate Linux-container probe exercises real restrictions. If that runtime is unavailable, retain the uncompleted execution competency explicitly. Completing policy fixtures is useful evidence, but it does not demonstrate file, network, process, or resource isolation.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. A Python policy rejects export but the process can call unrestricted open directly. What is missing?
2. A worker only reads one synthetic input and writes scratch. Which authority is unnecessary?
3. Only policy fixtures ran because Docker was unavailable. Honest competency statement?

Section 1.3 3 of 7

Container isolation and filesystem mounts

Focus

Use restricted mounts and process settings, then observe actual allowed and denied operations.

A container runs a process with a configured view of files, networking, and resources. Its security depends on that configuration and the underlying runtime. A bind mount exposes a host path inside the container; read-only mode prevents writes through that mount. A writable host mount grants real host-file authority even when the container's own root filesystem is read-only.

The taught probe mounts only a disposable folder at /work, read-only, and provides a small writable /tmp scratch area. It runs as a non-root numeric user, drops optional Linux capabilities, forbids privilege escalation, and limits processes and address space. Capabilities are granular privileges; dropping them reduces unnecessary authority. The process limit is deliberately one so a child launch must fail, while the existing Python worker can run.

The probe reads allowed.txt, writes scratch, attempts forbidden writes, attempts one harmless child, and tries a bounded allocation larger than its address-space limit. Catching PermissionError, an operating-system error, or MemoryError supplies observed enforcement evidence. Container isolation is not a universal guarantee against kernel defects or dangerous configuration. Docker runtime options provide the optional reference for these settings.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. Container root is read-only but /host-data is a writable host mount. Can it modify host-data?
2. Why run the probe as a non-root numeric user?
3. What makes a denied child-process check meaningful?

Section 1.4 4 of 7

Network egress and secret exposure

Focus

Restrict external routes and keep secrets outside the worker environment.

Network isolation and secret handling solve related but distinct problems. A worker without an external route cannot use that route to send data, but it might still disclose data through returned output or logs. A worker without a secret cannot leak that secret from its own memory, though other data may remain sensitive. Combine exposure reduction with channel restrictions.

The container command uses network none. The probe demonstrates that loopback communication inside its own network namespace still works, while a connection to reserved documentation address 192.0.2.1 fails. That destination is synthetic and no recipient is contacted. Inspect configuration as well as results: an arbitrary timeout on a normal network could reflect an unavailable endpoint rather than deliberate isolation.

Do not pass host environment variables or mount credential directories. The probe confirms a synthetic secret variable is absent and an unmounted canary path is unavailable. Absence alone is not proof of every host-file boundary; it complements the restricted mount configuration and observed write denials. Logs should contain outcomes and identifiers, not environment dumps. A container with the Docker control socket mounted would gain dangerous authority over the runtime and is outside this restricted design.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. A connection times out on an ordinary network. Does that alone prove configured egress isolation?
2. Network none blocks external routes. What other disclosure path still needs control?
3. Should a restricted worker receive the host Docker control socket?

Section 1.5 5 of 7

Put it into practice

Focus

Run the safe fixture, then use the documented container for actual runtime evidence.

Download week18.py, save it in an exercise folder, and run python week18.py --lesson 1. The default processor-only fixture finishes in seconds and explicitly reports that runtime isolation is NOT completed. This is the single practice workflow; its second stage requires Docker Desktop configured for Linux containers, a working engine, and the Python image download. No model or account is needed for the script. Do not treat unavailable runtime setup as a passed probe.

From PowerShell in that exercise folder, prepare only a disposable probe directory, then run:

New-Item -ItemType Directory -Force restricted-worker
Copy-Item -LiteralPath ./week18.py -Destination ./restricted-worker/week18.py
Set-Content -LiteralPath ./restricted-worker/allowed.txt -Value 'synthetic allowed' -Encoding ascii
$probePath = (Resolve-Path ./restricted-worker).Path
docker pull python:3.11-slim
docker run --rm --network none --read-only --user 65534:65534 --cap-drop ALL --security-opt no-new-privileges --pids-limit 8 --memory 128m --memory-swap 128m --cpus 1 --tmpfs /tmp:rw,noexec,nosuid,size=16m --mount "type=bind,source=$probePath,target=/work,readonly" python:3.11-slim python -c "import resource, runpy, sys; resource.setrlimit(resource.RLIMIT_AS, (100000000,100000000)); resource.setrlimit(resource.RLIMIT_NPROC, (1,1)); sys.argv=['/work/week18.py','--lesson','1','--runtime-probe']; runpy.run_path('/work/week18.py', run_name='__main__')"

The image download needs network and disk space; the worker itself has no external network. Record the image digest for reproducibility. The trusted bootstrap uses Python's standard-library resource module to lower both soft and hard address-space limits to 100,000,000 bytes and process limits to one before running the fixed worker through runpy.run_path. sys.argv supplies its command arguments. Setting the process limit after the initial Python process starts avoids startup failures caused by shared user-identity accounting. The kernel enforces the lowered hard limits; this non-root worker with dropped capabilities cannot raise them again. Docker separately enforces an outer eight-process bound and 128-mebibyte memory ceiling through control groups. The probe expects control groups version 2, a kernel resource-accounting interface, and verifies memory.max plus actual bounded allocation denial. A failed assertion remains an incomplete check requiring diagnosis, never permission to remove a limit and report success.

Download this week’s Python lab ↓

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. Default python week18.py --lesson 1 prints fixture preparation only. Has runtime enforcement passed?
2. Why mount only restricted-worker rather than the entire exercise drive?
3. The runtime probe fails its process-denial assertion. Correct response?

Section 1.6 6 of 7

Guided comparison

Focus

Interpret observed runtime outcomes separately from fixture-policy checks.

A successful runtime report contains allowed read mount, scratch write, and loopback communication. These demonstrate that the worker still performs required work. It also reports failed writes to the read-only input and root filesystem, failed external routing, failed child creation, and a caught MemoryError for a 128-mebibyte allocation under the smaller address-space limit. A mebibyte is 1,048,576 bytes.

The probe checks the actual process resource limit and the control-group memory ceiling, rather than merely printing the command's desired values. The child attempt uses the same trusted Python executable to print a harmless string. It is not a fork bomb. The allocation is bounded and caught; the separate address-space limit is chosen to deny it before container memory exhaustion. No arbitrary generated code runs.

These observations establish this worker's tested boundaries under this configuration. They do not prove the absence of every container escape or protect files later mounted writable. Preserve command, image digest, runtime version, output, and failures. If Docker is unavailable or access to its daemon is denied, report fixture success separately and runtime not run. That explicit result preserves the competency gap for later completion.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. The probe reads input and writes scratch while forbidden writes fail. Why test both sides?
2. Why catch a bounded MemoryError instead of allocating until the container crashes?
3. Docker daemon access is denied before the container starts. What runtime evidence exists?

Section 1.7 7 of 7

A writable host mount in a worker container

Focus

Recognize that a writable host mount bypasses the intended disposable-file boundary.

A worker container has a read-only root filesystem but mounts an entire project directory at /project with write access. The task only needs one source fixture. A generated program overwrites a project configuration through /project. The container did exactly what its mount permissions allowed; a read-only root did not protect the separate writable mount.

The worked repair replaces that mount with a read-only disposable input directory and a bounded temporary output area. The host integrator copies out only validated result files after the worker exits. It never mounts the home directory, credential folders, or runtime control socket. A synthetic forbidden target can then be tested without risking a real project file.

This transfer explains why isolation must be reviewed as effective authority rather than a product label. Containerized does not specify what is mounted, which user runs, what network routes exist, or what resources are limited. Inspect those choices and observe allowed and denied behavior. If the task genuinely needs to modify a host artifact, stage a candidate in scratch and authorize publication separately against exact paths and content identities instead of granting the worker broad project write access.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. Why did read-only root fail to protect a writable /project bind mount?
2. Safer publication pattern for generated output?
3. Does the word containerized establish least privilege?

Your personal notes

Optional, ungraded, and saved only in this browser. Export a backup from the Academy homepage to keep them.

References and further reading
Ask your own AI assistant

Copy this prompt into an assistant you already use. Nothing is sent automatically, and your personal notes are not included.

Next lesson: Binding policy and approval to execution →