shield
shield
¶
Adapter for terok-shield egress firewall.
Creates per-task :class:Shield instances from the sandbox configuration.
Each task gets its own state_dir under {task_dir}/shield/.
make_shield(task_dir, cfg=None)
¶
Construct a per-task :class:Shield from sandbox configuration.
Builds a :class:ShieldConfig with state_dir scoped to task_dir.
Source code in src/terok_sandbox/shield.py
pre_start(container, task_dir, cfg=None)
¶
Return extra podman run args for egress firewalling.
Returns an empty list (no firewall args) when the dangerous
bypass_firewall_no_protection override is active.
Raises :class:SystemExit with setup instructions when the
podman environment requires one-time hook installation.
Source code in src/terok_sandbox/shield.py
down(container, task_dir, *, allow_all=False, cfg=None)
¶
Set shield to bypass mode (allow egress) for a running container.
When allow_all is True, also permits private-range (RFC 1918) traffic.
Source code in src/terok_sandbox/shield.py
up(container, task_dir, cfg=None)
¶
Set shield to deny-all mode for a running container.
state(container, task_dir, cfg=None)
¶
Return the live shield state for a running container.
Queries actual nft state even when bypass is set, because containers started before bypass was enabled may still have active rules.
Source code in src/terok_sandbox/shield.py
status(cfg=None)
¶
Return shield status dict from the sandbox configuration.
Source code in src/terok_sandbox/shield.py
check_environment(cfg=None)
¶
Check the podman environment for shield compatibility.
Returns a synthetic :class:EnvironmentCheck with bypass info when the
dangerous bypass override is active.
Source code in src/terok_sandbox/shield.py
run_setup(*, root=False, user=False)
¶
Install global OCI hooks for shield egress firewalling.
Global hooks are required on all podman versions to survive container stop/start cycles (terok-shield#122).
Raises :class:SystemExit when neither --root nor --user is given.
Source code in src/terok_sandbox/shield.py
setup_hooks_direct(*, root=False)
¶
Install global hooks via the terok-shield Python API (no subprocess).
Suitable for TUI callers that need direct control. Installs hooks to the system directory (with sudo) when root is True, otherwise to the user directory.