Skip to content

config

config

Sandbox configuration — plain dataclass for standalone and embedded use.

SandboxConfig captures directory paths and settings that sandbox modules need. In standalone terok-sandbox use, it is resolved from environment variables and XDG defaults. When embedded in terok, the orchestration layer constructs it from core.config values.

CredentialsConfigError(config_paths, *, uses_removed_key=False)

Bases: RuntimeError

Global configuration prevents safe access to passphrase sources.

config_paths identifies the failing file for read/parse failures, or the loaded global configuration sources for merged validation failures. Diagnostics never include configuration values.

Record absolute source paths and an optional fixed migration hint.

Source code in src/terok_sandbox/config.py
def __init__(self, config_paths: tuple[Path, ...], *, uses_removed_key: bool = False) -> None:
    """Record absolute source paths and an optional fixed migration hint."""
    self.config_paths = tuple(path.absolute() for path in config_paths)
    message = (
        "Cannot read or validate credentials configuration; "
        "check global configuration before accessing passphrase sources:\n"
        + "\n".join(f"  {str(path)!r}" for path in self.config_paths)
    )
    if uses_removed_key:
        message += (
            "\nRename credentials.use_keyring to credentials.use_desktop_keyring; "
            "the old key is no longer supported."
        )
    super().__init__(message)

config_paths = tuple(path.absolute() for path in config_paths) instance-attribute

SandboxConfig(state_dir=_state_root(), runtime_dir=_runtime_root(), config_dir=_config_root(), vault_dir=_vault_root(), gate_port=_default_gate_port(), token_broker_port=_default_token_broker_port(), ssh_signer_port=_default_ssh_signer_port(), shield_profiles=(), shield_audit=_default_shield_audit(), shield_dnsmasq_path=_default_shield_dnsmasq_path(), shield_bypass_duration=_default_shield_bypass_duration(), shield_disabled=False, credentials_use_desktop_keyring=_default_credentials_use_desktop_keyring(), credentials_passphrase_command=_default_credentials_passphrase_command(), services_mode=_default_services_mode(), clearance=_default_services_clearance(), clearance_verdict_ttl=_default_clearance_verdict_ttl(), experimental=_default_experimental(), aslr_control=_default_aslr_control(), hosts_file=_default_hosts_file()) dataclass

Immutable configuration for the sandbox layer.

All paths default to the XDG/FHS-resolved values from paths. Override individual fields when constructing from terok's global config or when using terok-sandbox standalone.

state_dir = field(default_factory=_state_root) class-attribute instance-attribute

Writable state root (tokens, gate repos, task data).

runtime_dir = field(default_factory=_runtime_root) class-attribute instance-attribute

Transient runtime directory (PID files, sockets).

config_dir = field(default_factory=_config_root) class-attribute instance-attribute

Sandbox-scoped configuration root.

Note: shield profiles are resolved by shield_profiles_dir via namespace_config_root, not from this directory.

vault_dir = field(default_factory=_vault_root) class-attribute instance-attribute

Shared vault directory (DB, routes, env mounts).

gate_port = field(default_factory=_default_gate_port) class-attribute instance-attribute

HTTP port for the gate server (None = auto-allocate via registry).

Default-factory reads gate_server.port from config.yml; missing or unset keys fall through to None so the port registry can pick one. Direct SandboxConfig(gate_port=…) always wins.

token_broker_port = field(default_factory=_default_token_broker_port) class-attribute instance-attribute

TCP port for the vault's token broker (None = auto-allocate via registry).

Default-factory reads vault.port from config.yml.

ssh_signer_port = field(default_factory=_default_ssh_signer_port) class-attribute instance-attribute

TCP port for the vault's SSH signer (None = auto-allocate via registry).

Default-factory reads vault.ssh_signer_port from config.yml.

shield_profiles = () class-attribute instance-attribute

Shield egress firewall profile names.

Shield applies no profile unless one is named here.

shield_audit = field(default_factory=_default_shield_audit) class-attribute instance-attribute

Whether shield audit logging is enabled.

Default-factory reads shield.audit from the layered config.yml via the RawShieldSection schema; missing/typo'd keys fall back to the schema's True default. Direct SandboxConfig(shield_audit=…) always wins.

shield_dnsmasq_path = field(default_factory=_default_shield_dnsmasq_path) class-attribute instance-attribute

The dnsmasq binary shield runs; None lets shield find one on PATH.

Default-factory reads shield.dnsmasq_path from the layered config.yml. Set for a dnsmasq built outside the distro package.

shield_bypass_duration = field(default_factory=_default_shield_bypass_duration) class-attribute instance-attribute

How long the timed bypass window stays open when a caller names no duration.

Default-factory reads shield.bypass_duration from the layered config.yml. An nft timeout: a non-zero count and one unit (30s, 5m, 2h). The schema checks the configured value at load: one shield could not arm warns and falls back to the default. A value passed here directly is checked by shield, when a window is opened without a duration of its own.

shield_disabled = False class-attribute instance-attribute

DANGEROUS: when True, the egress firewall is completely disabled.

Hardcoded False here — sandbox refuses to read this field from config.yml because the layered chain includes a user-writable scope (~/.config/terok/config.yml) and an $ENV-controllable override (TEROK_CONFIG_FILE), so anything that drops a file in $HOME could silently disable the egress firewall. Orchestrators that want the kill-switch must pass it explicitly to SandboxConfig(shield_disabled=True) after resolving from their own trusted source.

credentials_use_desktop_keyring = field(default_factory=_default_credentials_use_desktop_keyring) class-attribute instance-attribute

Switch for the desktop keyring tier in the passphrase resolution chain.

On by default — an empty desktop keyring simply doesn't resolve, so the tier costs nothing until something lands a value there. Operators who want the chain to stay away from Secret Service entirely (its ACLs are per-collection, not per-item, so authorising terok against the default collection grants read access to every other secret stored there) set credentials.use_desktop_keyring: false.

credentials_passphrase_command = field(default_factory=_default_credentials_passphrase_command) class-attribute instance-attribute

Operator-supplied shell command that prints the SQLCipher passphrase on stdout.

Resolver tier slotted below the session cache and above the interactive prompt. Canonical headless option for hosts without systemd ≥ 257 — same shape as git config credential.helper or BORG_PASSCOMMAND. Read from credentials.passphrase_command in config.yml at construct time; None (the default) means "no helper configured" and the resolver skips this tier.

services_mode = field(default_factory=_default_services_mode) class-attribute instance-attribute

Transport for host↔container IPC, resolved once at construction.

Validated through the same RawServicesSection schema terok's RawGlobalConfig composes, so standalone and embedded paths agree on the value. Lives as an instance attribute rather than a free-function call per site so downstream code can't bypass config resolution — no manager without a SandboxConfig, every SandboxConfig carries a resolved mode.

clearance = field(default_factory=_default_services_clearance) class-attribute instance-attribute

Who is asked about a connection the shield refused: prompt, mute or off.

Default-factory reads services.clearance from the layered config.yml through the same RawServicesSection schema; orchestrators with per-project settings pass the resolved project value explicitly. It reaches the container's supervisor through the sidecar, which creation writes from this field (write_sidecar) and every start re-reads: off launches no verdict or clearance child, mute starts the clearance hub with the container muted, prompt puts each refusal to the operator. The shield refuses either way. A restart that should honour a changed setting rewrites the sidecar's copy first (Sandbox.clearance_refresh), so a change applies at the task's next start.

clearance_verdict_ttl = field(default_factory=_default_clearance_verdict_ttl) class-attribute instance-attribute

How long an unanswered clearance prompt stays pending, as clearance.verdict_ttl spells it.

Default-factory reads the key from the layered config.yml (clearance_verdict_ttl); None leaves the hub on its own default. It travels with clearance: creation writes it to the sidecar, the clearance child hands it to the hub it builds, and Sandbox.clearance_refresh rewrites it before a restart. The hub cannot read the key itself there, because the child is confined before the hub starts.

experimental = field(default_factory=_default_experimental) class-attribute instance-attribute

Whether the ecosystem-wide experimental: opt-in is on.

Cross-package switch: gates terok's krun runtime at task launch and sandbox's krun-only prereq probes (currently just ip) at terok-sandbox setup. Read from the top-level experimental: key in the layered config.yml at construct time; missing / typo'd values fall back to False. Direct SandboxConfig(experimental=…) always wins.

aslr_control = field(default_factory=_default_aslr_control) class-attribute instance-attribute

Allow task processes to disable their ASLR for sanitizer/debugging runs.

Defaults to run.aslr_control in the layered global config. Orchestrators pass the resolved project value explicitly to honor project overrides. Only narrowly vetted personality arguments are granted; the remaining host Podman seccomp policy stays intact. Disabled ASLR weakens exploit mitigation.

hosts_file = field(default_factory=_default_hosts_file) class-attribute instance-attribute

Base of the container's /etc/hosts, passed to podman as --hosts-file.

Defaults to run.hosts_file in the layered global config. Orchestrators pass the resolved project value explicitly to honor project overrides.

gate_base_path property

Return the gate server's repo base path.

shield_profiles_dir property

Return the directory for terok-managed shield profiles.

db_path property

Return the path to the vault sqlite3 database.

vault_socket_path property

Return the Unix socket path for the vault.

vault_pid_path property

Return the PID file path for the managed vault daemon.

vault_pending_passphrase_file property

Return the crash-recovery escrow for a passphrase change in flight.

change_passphrase writes the new value here before re-encrypting the DB and removes it once at least one tier holds it — so a crash between the rekey and the tier fan-out can never leave the DB encrypted under a key that exists nowhere. RAM-backed, owner-only, cleared on reboot; a distinct filename so the resolver chain never reads it as a live tier.

vault_rekey_stamp_file property

Return the marker whose mtime records the last passphrase change.

Touched by change_passphrase so health surfaces can flag supervisors that were spawned before the rekey — they keep the passphrase they resolved at spawn and need a restart to pick up the new one. Lives under runtime_dir deliberately: it vanishes on reboot together with every process it could possibly indict, so a stale stamp can never outlive the problem it describes.

vault_systemd_creds_file property

Return the sealed-credential path for the systemd-creds tier.

Lives under vault_dir (persistent state, 0o600) — the credential is machine-bound (TPM2 or host key), so persistence across reboots is the whole point. Written by terok-sandbox vault seal; read on every chain walk via terok_sandbox.vault.store.systemd_creds.

vault_recovery_marker_file property

Return the sidecar marker path for "operator saved the recovery passphrase".

Lives next to the sealed-credential file (persistent state, 0o600). A zero-byte file — deliberately no passphrase fingerprint (that would be an offline-guessing oracle, see terok_sandbox.vault.store.recovery), so a re-key does not auto-invalidate it; change_passphrase and vault lock drop the marker themselves.

routes_path property

Return the path to the vault route configuration JSON.

credential_audit_log_path property

Return the path to the credential-use audit JSONL.

One file under the vault state dir, shared across every subject the broker has ever served — sandbox doesn't model "subject" semantically, so per-subject layout is the consumer's concern (terok's review CLI filters by scope / subject).

ssh_signer_socket_path property

Return the Unix socket path for the vault's SSH signer.

The vault binds this socket and serves the SSH-agent protocol on it (clients use it as $SSH_AUTH_SOCK). Filename uses the protocol name so its purpose is recognisable to anyone tracing socket activity.

clone_cache_base_path property

Return the base directory for per-scope non-bare clone caches.

ssh_keys_dir property

Return the base directory for per-scope SSH keys.

with_resolved_ports()

Return a copy with TCP ports allocated via the shared port registry.

Idempotent — returns self (no copy) when there is nothing to allocate: socket mode never needs TCP listeners, and already-fully-resolved cfgs short-circuit.

Side-effectful: allocation hits the shared port registry, bind-tests each candidate, and persists the claim to state_dir/port-claims.json. Keep this call OUT of construction paths that don't actually launch services (sickbay checks, config inspection, tests) — that's why it's opt-in rather than baked into __post_init__. The consumers that do need real ports (ShieldManager, Sandbox) wrap their stored cfg in self._cfg = self._cfg.with_resolved_ports() at construction time so downstream code never sees None for the port it needs.

Source code in src/terok_sandbox/config.py
def with_resolved_ports(self) -> SandboxConfig:
    """Return a copy with TCP ports allocated via the shared port registry.

    Idempotent — returns ``self`` (no copy) when there is nothing
    to allocate: socket mode never needs TCP listeners, and
    already-fully-resolved cfgs short-circuit.

    **Side-effectful**: allocation hits the shared port registry,
    bind-tests each candidate, and persists the claim to
    ``state_dir/port-claims.json``.  Keep this call OUT of
    construction paths that don't actually launch services
    (sickbay checks, config inspection, tests) — that's why it's
    opt-in rather than baked into ``__post_init__``.  The
    consumers that *do* need real ports (``ShieldManager``,
    ``Sandbox``) wrap their stored cfg in
    ``self._cfg = self._cfg.with_resolved_ports()`` at construction
    time so downstream code never sees ``None`` for the port it
    needs.
    """
    if self.services_mode == "socket":
        return self
    if (
        self.gate_port is not None
        and self.token_broker_port is not None
        and self.ssh_signer_port is not None
    ):
        return self
    from dataclasses import replace

    from .port_registry import resolve_service_ports

    ports = resolve_service_ports(
        self.gate_port,
        self.token_broker_port,
        self.ssh_signer_port,
        gate_explicit=self.gate_port is not None,
        proxy_explicit=self.token_broker_port is not None,
        ssh_explicit=self.ssh_signer_port is not None,
        state_dir=self.state_dir,
    )
    return replace(
        self,
        gate_port=self.gate_port if self.gate_port is not None else ports.gate,
        token_broker_port=(
            self.token_broker_port if self.token_broker_port is not None else ports.proxy
        ),
        ssh_signer_port=(
            self.ssh_signer_port if self.ssh_signer_port is not None else ports.ssh_agent
        ),
    )

container_state_dir(container_name)

Host-side per-container state for launch plans and seccomp profiles.

Raises:

Type Description
ValueError

If container_name is not a safe single path component.

Source code in src/terok_sandbox/config.py
def container_state_dir(self, container_name: str) -> Path:
    """Host-side per-container state for launch plans and seccomp profiles.

    Raises:
        ValueError: If *container_name* is not a safe single path component.
    """
    _validate_container_name(container_name)
    return self.state_dir / "sandbox" / "runs" / container_name

sidecar_path(container_name)

The container's supervisor sidecar: state_dir/sidecar/<name>.json.

Keyed on the name, which is known before podman run: the launch path writes the file and pins it in the terok.sandbox.sidecar annotation before the container exists. Shared by write_sidecar, which creates it, and Sandbox.clearance_refresh, which edits it, so the edit always lands on the file creation wrote.

Raises:

Type Description
ValueError

If container_name is not a safe single path component.

Source code in src/terok_sandbox/config.py
def sidecar_path(self, container_name: str) -> Path:
    """The container's supervisor sidecar: ``state_dir/sidecar/<name>.json``.

    Keyed on the name, which is known before ``podman run``: the launch
    path writes the file and pins it in the ``terok.sandbox.sidecar``
    annotation before the container exists.  Shared by
    [`write_sidecar`][terok_sandbox.launch.write_sidecar], which creates
    it, and [`Sandbox.clearance_refresh`][terok_sandbox.Sandbox.clearance_refresh],
    which edits it, so the edit always lands on the file creation wrote.

    Raises:
        ValueError: If *container_name* is not a safe single path component.
    """
    _validate_container_name(container_name)
    return self.state_dir / "sidecar" / f"{container_name}.json"

container_runtime_dir(container_name)

Host-side per-container runtime dir, bind-mounted at /run/terok.

The single source of the runtime_dir/run/<name> convention: the launch path bind-mounts this directory into the container so the supervisor's service-specific socket directories (socket mode) surface beneath /run/terok/. A method, not a property, because it is keyed on the container name.

container_name must be a single safe path component — the returned path is mkdir'd, chmod'd, and rmtree'd by callers (ensure_container_runtime_dir, remove_container_state), so a name carrying a separator or .. (or an absolute path, which Path.__truediv__ would let swallow the whole prefix) could redirect those mutations outside the runtime dir. This is the same guard write_sidecar and the supervisor's load_sidecar apply at their entry points.

Raises:

Type Description
ValueError

If container_name is empty or not a single path component (contains a separator or NUL, or is ./..).

Source code in src/terok_sandbox/config.py
def container_runtime_dir(self, container_name: str) -> Path:
    """Host-side per-container runtime dir, bind-mounted at ``/run/terok``.

    The single source of the ``runtime_dir/run/<name>`` convention:
    the launch path bind-mounts this directory into the container so
    the supervisor's service-specific socket directories (socket
    mode) surface beneath ``/run/terok/``.  A method, not a property,
    because it is keyed on the container name.

    *container_name* must be a single safe path component — the
    returned path is ``mkdir``'d, ``chmod``'d, and ``rmtree``'d by
    callers ([`ensure_container_runtime_dir`][terok_sandbox.config.SandboxConfig.ensure_container_runtime_dir],
    [`remove_container_state`][terok_sandbox.launch.remove_container_state]),
    so a name carrying a separator or ``..`` (or an absolute path,
    which ``Path.__truediv__`` would let swallow the whole prefix)
    could redirect those mutations outside the runtime dir.  This is
    the same guard [`write_sidecar`][terok_sandbox.launch.write_sidecar]
    and the supervisor's ``load_sidecar`` apply at their entry points.

    Raises:
        ValueError: If *container_name* is empty or not a single path
            component (contains a separator or NUL, or is ``.``/``..``).
    """
    _validate_container_name(container_name)
    return self.runtime_dir / "run" / container_name

ensure_container_runtime_dir(container_name)

(Re)create container_runtime_dir (mode 0700) and return it.

Idempotent, and it must be re-callable: the directory is gone for two routine reasons by the time a stopped container restarts — it lives under runtime_dir ($XDG_RUNTIME_DIR), a tmpfs the OS clears on reboot, and the per-container supervisor rmtrees it on every stop. podman start re-binds the /run/terok mount from this exact source, so it must exist first. A plain stop/start survives because podman recreates the leaf while its parent lives; a reboot wipes the whole …/run chain and mkdir(parents=True) is what rebuilds it.

Source code in src/terok_sandbox/config.py
def ensure_container_runtime_dir(self, container_name: str) -> Path:
    """(Re)create [`container_runtime_dir`][terok_sandbox.config.SandboxConfig.container_runtime_dir] (mode 0700) and return it.

    Idempotent, and it must be re-callable: the directory is gone for
    two routine reasons by the time a stopped container restarts — it
    lives under ``runtime_dir`` (``$XDG_RUNTIME_DIR``), a tmpfs the OS
    clears on reboot, and the per-container supervisor
    ``rmtree``s it on every stop.  ``podman start`` re-binds the
    ``/run/terok`` mount from this exact source, so it must exist
    first.  A plain stop/start survives because podman recreates the
    leaf while its parent lives; a reboot wipes the whole ``…/run``
    chain and ``mkdir(parents=True)`` is what rebuilds it.
    """
    run_dir = self.container_runtime_dir(container_name)
    run_dir.mkdir(parents=True, exist_ok=True)
    run_dir.chmod(0o700)
    return run_dir

open_credential_db(db_path=None, *, prompt_on_tty=False)

Open the credentials DB with this config's resolution-chain knobs.

Single seam over open_credential_db so call sites never plumb tier-selection kwargs by hand — adding a new tier is one entry in the private _chain_kwargs helper, no cross-package fan-out.

db_path defaults to self.db_path; callers that already hold a path (a sidecar-pinned DB path, or a test override) pass it explicitly so the open targets that DB while still using this config's tier policy. CLI consumers pass prompt_on_tty=True to unlock the interactive fallback; the per-container supervisor leaves it off.

Source code in src/terok_sandbox/config.py
def open_credential_db(
    self, db_path: Path | None = None, *, prompt_on_tty: bool = False
) -> Any:
    """Open the credentials DB with this config's resolution-chain knobs.

    Single seam over [`open_credential_db`][terok_sandbox.vault.store.db.open_credential_db]
    so call sites never plumb tier-selection kwargs by hand — adding
    a new tier is one entry in the private ``_chain_kwargs`` helper,
    no cross-package fan-out.

    *db_path* defaults to ``self.db_path``; callers that already
    hold a path (a sidecar-pinned DB path, or a test override) pass
    it explicitly so the open targets that DB while still using
    this config's tier policy.  CLI consumers pass
    ``prompt_on_tty=True`` to unlock the interactive fallback;
    the per-container supervisor leaves it off.
    """
    from .vault.store.db import open_credential_db  # noqa: PLC0415

    return open_credential_db(
        db_path if db_path is not None else self.db_path,
        **self._chain_kwargs(prompt_on_tty=prompt_on_tty),
    )

open_credential_db_with_source(db_path=None, *, prompt_on_tty=False)

Same as open_credential_db but also returns which tier of the chain hit.

db_path override semantics match open_credential_db. The returned source lets callers (status reports, the supervisor startup log) name which tier unlocked the vault instead of second-guessing the resolver.

Source code in src/terok_sandbox/config.py
def open_credential_db_with_source(
    self, db_path: Path | None = None, *, prompt_on_tty: bool = False
) -> tuple[CredentialDB, PassphraseTier]:
    """Same as [`open_credential_db`][terok_sandbox.SandboxConfig.open_credential_db]
    but also returns which tier of the chain hit.

    *db_path* override semantics match
    [`open_credential_db`][terok_sandbox.SandboxConfig.open_credential_db].
    The returned source lets callers (status reports, the
    supervisor startup log) name which tier unlocked the vault
    instead of second-guessing the resolver.
    """
    from .vault.store.db import open_credential_db_with_source  # noqa: PLC0415

    return open_credential_db_with_source(
        db_path if db_path is not None else self.db_path,
        **self._chain_kwargs(prompt_on_tty=prompt_on_tty),
    )

open_sqlcipher_connection(db_path=None, **connect_kwargs)

Open a raw sqlcipher3 connection via the chain (vault daemon path).

Source code in src/terok_sandbox/config.py
def open_sqlcipher_connection(self, db_path: Path | None = None, **connect_kwargs: Any) -> Any:
    """Open a raw sqlcipher3 connection via the chain (vault daemon path)."""
    from .vault.store.encryption import open_sqlcipher_via_chain  # noqa: PLC0415

    return open_sqlcipher_via_chain(
        db_path or self.db_path,
        **self._chain_kwargs(prompt_on_tty=False),
        **connect_kwargs,
    )

resolve_passphrase(*, prompt_on_tty=False)

Walk the resolution chain with this config's knobs; return the passphrase or None.

Diagnostic seam — never opens the DB. Used by host-side doctor / sickbay and by vault seal to reuse whatever tier currently has the key. Same chain order as open_credential_db because both delegate here.

Source code in src/terok_sandbox/config.py
def resolve_passphrase(self, *, prompt_on_tty: bool = False) -> str | None:
    """Walk the resolution chain with this config's knobs; return the passphrase or ``None``.

    Diagnostic seam — never opens the DB.  Used by host-side
    doctor / sickbay and by ``vault seal`` to reuse whatever tier
    currently has the key.  Same chain order as
    [`open_credential_db`][terok_sandbox.SandboxConfig.open_credential_db]
    because both delegate here.
    """
    from .vault.store.encryption import resolve_passphrase  # noqa: PLC0415

    return resolve_passphrase(
        credentials_db=self.db_path, **self._chain_kwargs(prompt_on_tty=prompt_on_tty)
    )

resolve_passphrase_with_source(*, prompt_on_tty=False, credentials_db=None)

Walk the resolution chain with this config's knobs; return (passphrase, source).

Diagnostic counterpart to resolve_passphrase — feeds the daemon startup log so the operator sees which tier unlocked the vault on this boot.

credentials_db overrides which vault the session-cache lookup is scoped to; it defaults to this config's db_path. A caller opening a DB at a path other than the config default (the vault daemon, handed an explicit DB path) passes it so the cache lookup matches the DB it is about to open.

Source code in src/terok_sandbox/config.py
def resolve_passphrase_with_source(
    self, *, prompt_on_tty: bool = False, credentials_db: str | Path | None = None
) -> tuple[str | None, PassphraseTier | None]:
    """Walk the resolution chain with this config's knobs; return ``(passphrase, source)``.

    Diagnostic counterpart to
    [`resolve_passphrase`][terok_sandbox.SandboxConfig.resolve_passphrase]
    — feeds the daemon startup log so the operator sees *which*
    tier unlocked the vault on this boot.

    *credentials_db* overrides which vault the session-cache lookup
    is scoped to; it defaults to this config's ``db_path``.  A caller
    opening a DB at a path other than the config default (the vault
    daemon, handed an explicit DB path) passes it so the cache lookup
    matches the DB it is about to open.
    """
    from .vault.store.encryption import resolve_passphrase_with_source  # noqa: PLC0415

    return resolve_passphrase_with_source(
        credentials_db=credentials_db if credentials_db is not None else self.db_path,
        **self._chain_kwargs(prompt_on_tty=prompt_on_tty),
    )

ssh_signer_local_socket_path(scope)

Return the per-scope vault SSH-agent socket path for scope.

The vault binds one 0600 Unix socket per scope with at least one assigned key, under the same runtime_dir as the main signer. Host-side gate-sync points SSH_AUTH_SOCK at this path.

Rejects unsafe scope names with InvalidScopeName as a belt-and-braces guard — writers in the DB layer enforce the same policy, but the socket path is public API and may be called without a preceding DB write.

Source code in src/terok_sandbox/config.py
def ssh_signer_local_socket_path(self, scope: str) -> Path:
    """Return the per-scope vault SSH-agent socket path for *scope*.

    The vault binds one 0600 Unix socket per scope with at least one
    assigned key, under the same ``runtime_dir`` as the main signer.
    Host-side ``gate-sync`` points ``SSH_AUTH_SOCK`` at this path.

    Rejects unsafe scope names with [`InvalidScopeName`][terok_sandbox.vault.store.db.InvalidScopeName]
    as a belt-and-braces guard — writers in the DB layer enforce the
    same policy, but the socket path is public API and may be called
    without a preceding DB write.
    """
    from .vault.store.db import _require_safe_scope

    _require_safe_scope(scope)
    return self.runtime_dir / f"ssh-agent-local-{scope}.sock"

services_mode()

Resolve the services.mode setting through sandbox's own pydantic schema.

Source code in src/terok_sandbox/config.py
def services_mode() -> ServicesMode:
    """Resolve the ``services.mode`` setting through sandbox's own pydantic schema."""
    from .config_schema import RawServicesSection

    return _validate_section(RawServicesSection, "services").mode

services_clearance()

Resolve the services.clearance setting through sandbox's own pydantic schema.

Same section as services_mode. A value outside prompt / mute / off warns and reads as prompt — an unreadable setting asks the operator rather than silencing anyone — and costs that key alone: services.mode beside it keeps what the operator wrote (see RawServicesSection).

Source code in src/terok_sandbox/config.py
def services_clearance() -> ClearanceMode:
    """Resolve the ``services.clearance`` setting through sandbox's own pydantic schema.

    Same section as [`services_mode`][terok_sandbox.config.services_mode].
    A value outside ``prompt`` / ``mute`` / ``off`` warns and reads as
    ``prompt`` — an unreadable setting asks the operator rather than
    silencing anyone — and costs that key alone: ``services.mode`` beside
    it keeps what the operator wrote (see
    [`RawServicesSection`][terok_sandbox.config_schema.RawServicesSection]).
    """
    from .config_schema import RawServicesSection

    return _validate_section(RawServicesSection, "services").clearance

clearance_verdict_ttl()

Read clearance.verdict_ttl for the clearance hub, as the operator wrote it.

The key belongs to terok-clearance: its hub reads the key and owns the grammar. The hub runs in a supervisor child, though, and that child is confined before the hub starts. The operator's config.yml is outside what the child may read, because the file can hold the vault passphrase. So the launcher reads the key here, where the whole layered config is visible, and the value reaches the child in the sidecar.

The value is carried, not interpreted. It is read with the reader the hub itself uses, which gives the text of what the operator wrote, and the child parses it with the hub's own parser. The hub therefore gets what it would have read unconfined. This foundation module may not import terok-clearance, and a copy of the grammar here could only drift from the hub's. None means the key is unset.

Source code in src/terok_sandbox/config.py
def clearance_verdict_ttl() -> str | None:
    """Read ``clearance.verdict_ttl`` for the clearance hub, as the operator wrote it.

    The key belongs to terok-clearance: its hub reads the key and owns
    the grammar.  The hub runs in a supervisor child, though, and that
    child is confined before the hub starts.  The operator's
    ``config.yml`` is outside what the child may read, because the file
    can hold the vault passphrase.  So the launcher reads the key here,
    where the whole layered config is visible, and the value reaches the
    child in the sidecar.

    The value is carried, not interpreted.  It is read with the reader
    the hub itself uses, which gives the text of what the operator wrote,
    and the child parses it with the hub's own parser.  The hub therefore
    gets what it would have read unconfined.  This foundation module may
    not import terok-clearance, and a copy of the grammar here could only
    drift from the hub's.  ``None`` means the key is unset.
    """
    return read_config_section("clearance").get("verdict_ttl")

credentials_use_desktop_keyring()

Read the current desktop-keyring policy from credentials.use_desktop_keyring.

Source code in src/terok_sandbox/config.py
def credentials_use_desktop_keyring() -> bool:
    """Read the current desktop-keyring policy from ``credentials.use_desktop_keyring``."""
    return _credentials_section().use_desktop_keyring

credentials_passphrase_command()

Resolve the credentials.passphrase_command shell-helper recipe through the schema.

Source code in src/terok_sandbox/config.py
def credentials_passphrase_command() -> str | None:
    """Resolve the ``credentials.passphrase_command`` shell-helper recipe through the schema."""
    return _credentials_section().passphrase_command

shield_audit()

Resolve the shield.audit setting through the schema.

Source code in src/terok_sandbox/config.py
def shield_audit() -> bool:
    """Resolve the ``shield.audit`` setting through the schema."""
    return _shield_section().audit

shield_dnsmasq_path()

Resolve the shield.dnsmasq_path setting through the schema.

Source code in src/terok_sandbox/config.py
def shield_dnsmasq_path() -> Path | None:
    """Resolve the ``shield.dnsmasq_path`` setting through the schema."""
    return _shield_section().dnsmasq_path

shield_bypass_duration()

Resolve the shield.bypass_duration setting through the schema.

A value shield could not arm warns and reads as the default, and costs that key alone: the rest of the shield: section — the kill-switch among it — keeps what the operator wrote.

Source code in src/terok_sandbox/config.py
def shield_bypass_duration() -> str:
    """Resolve the ``shield.bypass_duration`` setting through the schema.

    A value shield could not arm warns and reads as the default, and costs
    that key alone: the rest of the ``shield:`` section — the kill-switch
    among it — keeps what the operator wrote.
    """
    return _shield_section().bypass_duration

experimental_enabled()

Resolve the top-level experimental: opt-in from the layered config.

Ecosystem-wide flag: shared between sandbox (krun host-binary prereqs), executor (krun runtime construction), and terok (krun runtime selection at task launch). Defaults to False when the key is absent or malformed.

Source code in src/terok_sandbox/config.py
def experimental_enabled() -> bool:
    """Resolve the top-level ``experimental:`` opt-in from the layered config.

    Ecosystem-wide flag: shared between sandbox (krun host-binary
    prereqs), executor (krun runtime construction), and terok (krun
    runtime selection at task launch).  Defaults to ``False`` when the
    key is absent or malformed.
    """
    raw = read_config_top_level("experimental")
    if isinstance(raw, bool):
        return raw
    return False

gate_server_port()

Resolve gate_server.port through the schema; None = auto-allocate.

Source code in src/terok_sandbox/config.py
def gate_server_port() -> int | None:
    """Resolve ``gate_server.port`` through the schema; ``None`` = auto-allocate."""
    return _gate_server_section().port

vault_token_broker_port()

Resolve vault.port through the schema; None = auto-allocate.

Source code in src/terok_sandbox/config.py
def vault_token_broker_port() -> int | None:
    """Resolve ``vault.port`` through the schema; ``None`` = auto-allocate."""
    return _vault_section().port

vault_ssh_signer_port()

Resolve vault.ssh_signer_port through the schema; None = auto-allocate.

Source code in src/terok_sandbox/config.py
def vault_ssh_signer_port() -> int | None:
    """Resolve ``vault.ssh_signer_port`` through the schema; ``None`` = auto-allocate."""
    return _vault_section().ssh_signer_port