Skip to content

feat(py): the construction-time sandbox gate and the worker's address-space limit - #352

Draft
jat255 wants to merge 1 commit into
mainfrom
jat255/t7d4-sandbox-gate-rlimits
Draft

feat(py): the construction-time sandbox gate and the worker's address-space limit#352
jat255 wants to merge 1 commit into
mainfrom
jat255/t7d4-sandbox-gate-rlimits

Conversation

@jat255

@jat255 jat255 commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

This PR adds protection_mode(), which decides before an agent is built whether this host can sandbox the code execution worker, and the 8 GiB address-space cap the worker puts on itself at startup. Nothing calls the gate yet; run_python registration wires it in.

Agent-written detail

sandbox_capabilities() is the shape the four ctypes probes fill in. Until they exist it reports every mechanism unavailable, so the gate refuses every host. That is why it is not wired into Commons.__init__ here: doing so now would abort construction everywhere, for a tool that is not registered yet.

Two departures from run_r_protection_mode(). The opt-in is COMMONS_ALLOW_UNSAFE_FALLBACK rather than an option, and there is deliberately no keyword for it, so accepting weaker protection takes an act outside the code. Only the address-space limit is set, not a CPU limit: RLIMIT_CPU is cumulative over the worker's whole life, so a long session would be killed mid-call rather than hit the parent's per-call timeout. Noted on kata t7d4.

A kernel that will not set RLIMIT_AS is reported rather than treated as fatal. Recent macOS is such a kernel, so the three clamp tests skip locally and run on the Ubuntu leg of CI.

roborev flagged the protection-mode decision table as a cross-language contract held twice, once per suite. Fixing it here would pull pkg-r/ into a Python-only task, so kata dkev, which already owns the shared sandbox fixture, has been widened to cover the table.

…-space limit

protection_mode() decides, before an agent is built, whether this host can
sandbox the code execution worker: Linux needs seccomp plus either Landlock or
unprivileged user namespaces, macOS needs seatbelt, and anything else is
refused. A refusal names the reason and what to check. COMMONS_ALLOW_UNSAFE_
FALLBACK downgrades it to guardrails; there is no keyword for it, because
accepting weaker protection should take a deliberate act outside the code.

sandbox_capabilities() is the shape the four ctypes probes fill in. Until they
exist it reports every mechanism unavailable, which refuses every host. Nothing
calls the gate yet: run_python registration wires it in.

_runtime/ holds what mutates the worker process, starting with the 8 GiB
address-space cap. A smaller inherited limit wins, and a kernel that will not
set RLIMIT_AS at all is reported rather than treated as fatal, since the cap
guards against a runaway allocation and is not the security boundary.
@jat255
jat255 force-pushed the jat255/t7d4-sandbox-gate-rlimits branch from 4078c63 to 445d22e Compare September 11, 2026 19:47
@jat255
jat255 added this pull request to stack #364 September 11, 2026 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-manual-review Agent-created work that needs a human review py Affects the Python implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant