A container is one layer in a code-execution boundary, not a reason to run arbitrary source with ordinary application privileges. The threat model includes filesystem access, network access, resource exhaustion, process creation, kernel vulnerabilities, and escape attempts.
Keep the runner disposable
Use an isolated worker with no application secrets, no Docker socket, and no host mounts containing sensitive data. Disable network access unless the task explicitly needs it. Run as a non-root user, drop capabilities, use a restrictive seccomp profile, and make the root filesystem read-only where possible. Consider stronger isolation such as a sandboxed runtime or dedicated virtual machines when the risk requires it.
Apply hard limits to CPU, memory, process count, wall-clock time, output size, file size, and concurrent jobs. A timeout must terminate the whole process tree and clean up temporary storage. Reuse immutable runtime images rather than allowing a submitted program to choose arbitrary images or compiler commands.
Protect the control plane
The API should enqueue a constrained job and receive bounded results; it should not run untrusted code in the web process. Validate language and source size before scheduling. Separate runner credentials and network routes from the control plane. Treat stdout and stderr as untrusted text in the UI.
Test escape-oriented cases, fork bombs, infinite loops, large output, network access, and worker crashes in a controlled environment. Review Docker and kernel security updates. The safety of a code runner depends on defense in depth and ongoing operational testing.
Verify isolation at the boundary you plan to operate
Containers use operating-system isolation features and share the host kernel. Docker's security documentation describes the daemon, namespaces, control groups, and other settings that affect the boundary. Resource controls constrain what a container can consume. A production runner also needs a threat model that accounts for the host, neighboring workloads, filesystem mounts, and the people who control those settings. Docker Engine security · Docker resource constraints
Run workload fixtures only in an isolated environment. Start with a known successful calculation, then check how the runner reports a defined deadline, a memory limit, and an output cap using safe test programs. Confirm that the runner releases the slot and deletes job artifacts after each outcome. Keep secrets outside the execution environment and keep network access disabled unless the use case and the isolation design account for it.
Worked example
This runs a known expression in a restricted local container. Hostile code needs a separate threat model, enforced wall-clock termination, controlled filesystem mounts, and isolation beyond these example flags.
shdocker run --rm --network none --read-only --cap-drop ALL \ --security-opt no-new-privileges --pids-limit 32 --memory 128m --cpus 0.5 \ --user 65534:65534 node:24-alpine node -e 'console.log(2 + 3)'




Community
Discussion
Loading comments…