Skip to content

The agent that grows with you

fix(cron): no_agent scripts get the owning profile's declared secret, never the launch profile's

teknium1802a9975d283
diff --git a/cron/scheduler_script.py b/cron/scheduler_script.py
index e78b933c929..eccf11a5d12 100644
--- a/cron/scheduler_script.py
+++ b/cron/scheduler_script.py
@@ -343,7 +343,7 @@ def _run_job_script(
return False, err
try:
- from tools.environments.local import build_subprocess_env
+ from tools.environments.local import build_subprocess_env, strip_launch_profile_env
popen_kwargs: dict[str, Any] = {"start_new_session": True}
if sys.platform == "win32":
popen_kwargs = {
@@ -355,7 +355,11 @@ def _run_job_script(
# reader threads on non-UTF-8 Windows (#45099).
"encoding": "utf-8",
"errors": "replace"}
- env = build_subprocess_env()
+ # The process env is the LAUNCH profile's. For a job owned by a routed profile, drop that
+ # profile's .env residue from the base first (no-op for the launch profile's own jobs);
+ # the sanitizer then overlays the names the owning profile declares in
+ # terminal.env_passthrough from its own secret scope (#114209).
+ env = build_subprocess_env(strip_launch_profile_env(os.environ.copy()))
env.update(env_overlay)
# Subprocess cwd only (default: scripts-dir parent). NEVER os.chdir() the process.
# Use the job's workdir as the subprocess cwd when configured, otherwise default to the scripts-dir
diff --git a/tests/cron/test_cron_no_agent.py b/tests/cron/test_cron_no_agent.py
index cb51a046403..a72f401af7b 100644
--- a/tests/cron/test_cron_no_agent.py
+++ b/tests/cron/test_cron_no_agent.py
@@ -137,6 +137,62 @@ def test_run_job_no_agent_reloads_dotenv_before_script(hermes_env, monkeypatch):
assert str(loaded_homes[0]) == str(hermes_env)
+_PRESENCE_PROBE = (
+ "#!/bin/bash\n"
+ 'for n in JOB_SVC_TOKEN LAUNCH_ONLY_TOKEN; do [ -n "${!n}" ] && echo "$n=set" || echo "$n=MISSING"; done\n'
+)
+
+
+def test_no_agent_script_gets_owning_profiles_declared_secret_never_launch_residue(
+ hermes_env, monkeypatch, tmp_path,
+):
+ """Routed profile B declares JOB_SVC_TOKEN in terminal.env_passthrough and defines it only in
+ its own .env (never in the process env); the launch profile A's .env credential is in the
+ process env. B's script sees its own secret and not A's (#114209)."""
+ from agent.secret_scope import (
+ build_profile_secret_scope, reset_secret_scope, set_multiplex_active, set_secret_scope)
+ from cron.scheduler_script import _run_job_script
+ from hermes_constants import reset_hermes_home_override, set_hermes_home_override
+
+ (hermes_env / ".env").write_text("LAUNCH_ONLY_TOKEN=launch-secret\n", encoding="utf-8")
+ monkeypatch.setenv("LAUNCH_ONLY_TOKEN", "launch-secret") # what load_hermes_dotenv() did at startup
+ monkeypatch.delenv("JOB_SVC_TOKEN", raising=False)
+ routed = tmp_path / "routed"
+ (routed / "scripts").mkdir(parents=True)
+ (routed / ".env").write_text("JOB_SVC_TOKEN=routed-secret\n", encoding="utf-8")
+ (routed / "config.yaml").write_text("terminal:\n env_passthrough: [JOB_SVC_TOKEN]\n", encoding="utf-8")
+ (routed / "scripts" / "probe.sh").write_text(_PRESENCE_PROBE, encoding="utf-8")
+
+ set_multiplex_active(True)
+ home_token = set_hermes_home_override(str(routed))
+ scope_token = set_secret_scope(build_profile_secret_scope(routed))
+ try:
+ ok, output = _run_job_script("probe.sh")
+ finally:
+ reset_secret_scope(scope_token)
+ reset_hermes_home_override(home_token)
+ set_multiplex_active(False)
+
+ assert ok is True
+ assert output.splitlines() == ["JOB_SVC_TOKEN=set", "LAUNCH_ONLY_TOKEN=MISSING"]
+
+
+def test_no_agent_script_of_launch_profile_keeps_its_own_env_credential(hermes_env, monkeypatch):
+ """Single-profile documented flow: the launch profile's own script still inherits the
+ credential its .env put in the process env — nothing is stripped for a non-routed job."""
+ from cron.scheduler_script import _run_job_script
+
+ (hermes_env / ".env").write_text("LAUNCH_ONLY_TOKEN=launch-secret\n", encoding="utf-8")
+ monkeypatch.setenv("LAUNCH_ONLY_TOKEN", "launch-secret")
+ monkeypatch.delenv("JOB_SVC_TOKEN", raising=False)
+ (hermes_env / "scripts" / "probe.sh").write_text(_PRESENCE_PROBE, encoding="utf-8")
+
+ ok, output = _run_job_script("probe.sh")
+
+ assert ok is True
+ assert output.splitlines() == ["JOB_SVC_TOKEN=MISSING", "LAUNCH_ONLY_TOKEN=set"]
+
+
def test_timed_out_no_agent_script_delivery_is_not_mislabeled_as_provider_failure(
hermes_env, monkeypatch,
):
diff --git a/tests/tools/test_env_passthrough.py b/tests/tools/test_env_passthrough.py
index 9afb4948a74..00d19f991b0 100644
--- a/tests/tools/test_env_passthrough.py
+++ b/tests/tools/test_env_passthrough.py
@@ -252,6 +252,32 @@ class TestTerminalIntegration:
assert "SERVICE_TOKEN" not in child_env
+ def test_scope_only_declared_name_reaches_every_local_child(self, monkeypatch):
+ """A routed profile's declared secret lives only in its scope (its .env never enters the
+ process env), so it must be added from the scope on every local spawn surface; an
+ undeclared scope entry stays out. No scope bound -> byte-identical single-profile env."""
+ from tools.code_execution_env import _scrub_child_env
+ from tools.environments.local import _sanitize_subprocess_env
+
+ register_env_passthrough(["SERVICE_TOKEN"])
+ monkeypatch.delenv("SERVICE_TOKEN", raising=False)
+ base = {"PATH": "/usr/bin", "HOME": "/home/user"}
+ ss.set_multiplex_active(True)
+ token = ss.set_secret_scope({"SERVICE_TOKEN": "token-for-routed-profile",
+ "UNDECLARED_TOKEN": "never-forwarded"})
+ try:
+ terminal_env = _sanitize_subprocess_env(dict(base))
+ sandbox_env = _scrub_child_env(dict(base))
+ finally:
+ ss.reset_secret_scope(token)
+ ss.set_multiplex_active(False)
+
+ for child_env in (terminal_env, sandbox_env):
+ assert child_env["SERVICE_TOKEN"] == "token-for-routed-profile"
+ assert "UNDECLARED_TOKEN" not in child_env
+ assert "SERVICE_TOKEN" not in _sanitize_subprocess_env(dict(base))
+ assert "SERVICE_TOKEN" not in _scrub_child_env(dict(base))
+
def test_shared_local_snapshot_re_resolves_current_profile(self, monkeypatch, tmp_path):
"""A persistent shell snapshot must not retain the previous profile's value."""
from tools.environments.local import LocalEnvironment
diff --git a/tools/code_execution_env.py b/tools/code_execution_env.py
index c405d70e786..6dd3eb0b4d1 100644
--- a/tools/code_execution_env.py
+++ b/tools/code_execution_env.py
@@ -59,10 +59,11 @@ def _scrub_child_env(source_env, is_passthrough=None, is_windows=None):
OS-essential allowlist passes by exact name.
"""
try:
- from tools.env_passthrough import is_env_passthrough, resolve_passthrough_value
+ from tools.env_passthrough import is_env_passthrough, resolve_passthrough_value, scoped_passthrough_additions
except Exception:
is_env_passthrough = lambda _: False # noqa: E731
resolve_passthrough_value = lambda _name, _fallback: None # noqa: E731
+ scoped_passthrough_additions = lambda _present: {} # noqa: E731
if is_passthrough is None:
is_passthrough = is_env_passthrough
if is_windows is None:
@@ -85,6 +86,9 @@ def _scrub_child_env(source_env, is_passthrough=None, is_windows=None):
scrubbed[k] = v
elif k.startswith("HERMES_"):
_dropped_hermes.append(k)
+ # Declared names only the bound profile scope holds (a routed profile's own .env / sources
+ # never enter the process env) — the loop above sees only names ``source_env`` carries.
+ scrubbed.update((k, v) for k, v in scoped_passthrough_additions(scrubbed).items() if is_passthrough(k))
if _dropped_hermes:
logger.debug(
"execute_code: dropped %d non-allowlisted HERMES_* var(s) from the "
diff --git a/tools/env_passthrough.py b/tools/env_passthrough.py
index aeac256f9af..e5fd6847fd3 100644
--- a/tools/env_passthrough.py
+++ b/tools/env_passthrough.py
@@ -141,6 +141,29 @@ def resolve_passthrough_value(name: str, fallback: str | None = None) -> str | N
return get_secret(name, None if multiplex_active else fallback)
+def scoped_passthrough_additions(present: Iterable[str]) -> dict[str, str]:
+ """Declared passthrough names the bound profile secret scope supplies but the env being
+ filtered (*present*) lacks. A routed profile's ``.env`` and hydrated sources never enter
+ ``os.environ`` (``load_hermes_dotenv`` skips the process-global load for a routed home), so a
+ name-by-name filter over the process env can only forward a declared name the LAUNCH profile
+ also happens to define — the served profile's own value has no way in (#114209). Reads the
+ bound scope alone: never ``os.environ``, never another profile. Empty without a scope, so
+ single-profile spawns are byte-identical."""
+ from agent.secret_scope import _is_global_env, current_secret_scope
+ scope = current_secret_scope()
+ if not scope:
+ return {}
+ present = set(present)
+ additions: dict[str, str] = {}
+ for name in get_all_passthrough():
+ if name in present or _is_global_env(name):
+ continue
+ value = scope.get(name)
+ if value is not None:
+ additions[name] = value
+ return additions
+
+
def clear_env_passthrough() -> None:
"""Reset the skill-scoped allowlist (e.g. on session reset)."""
_get_allowed().clear()
diff --git a/tools/environments/local.py b/tools/environments/local.py
index 6a826376165..76493d77d0e 100644
--- a/tools/environments/local.py
+++ b/tools/environments/local.py
@@ -283,6 +283,13 @@ def _scrubbed_env(parts, plugin_strip: frozenset, fix_path) -> dict:
out: dict[str, str] = {}
for items, unwrap_force in parts:
_filter_secret_env(items, out, unwrap_force=unwrap_force, plugin_strip=plugin_strip)
+ # Declared names the bound profile scope holds but the process env never did (a routed
+ # profile's own .env / sources) — the filter above can only see names already present.
+ try:
+ from tools.env_passthrough import scoped_passthrough_additions
+ out.update((k, v) for k, v in scoped_passthrough_additions(out).items() if k not in plugin_strip)
+ except Exception:
+ logger.debug("Could not resolve scope-only passthrough names", exc_info=True)
path_key = _path_env_key(out)
# Keep bare ``hermes`` invocations available to child jobs even when the gateway was launched by a
# service manager or cron without the console script's directory on PATH. The terminal environment
@@ -637,8 +644,11 @@ def _path_env_key(run_env: dict) -> str | None:
def _make_run_env(env: dict) -> dict:
- """Build a run environment with a sane PATH and provider-var stripping."""
- return _scrubbed_env([(dict(os.environ | env), True)], frozenset(),
+ """Build a run environment with a sane PATH and provider-var stripping. The process env is
+ the LAUNCH profile's; under a routed home override its ``.env`` residue is dropped first
+ (``strip_launch_profile_env``, a no-op for the launch profile) so the backend's own ``env``
+ and the served profile's declared passthrough names are what the child sees."""
+ return _scrubbed_env([(dict(strip_launch_profile_env(os.environ.copy()) | env), True)], frozenset(),
lambda p: _prepend_git_bash_dirs(_append_missing_sane_path_entries(p)))
diff --git a/website/docs/user-guide/features/cron.md b/website/docs/user-guide/features/cron.md
index 9802b9ba89b..05863ffc27a 100644
--- a/website/docs/user-guide/features/cron.md
+++ b/website/docs/user-guide/features/cron.md
@@ -868,6 +868,18 @@ Semantics:
`.sh` / `.bash` files run under `bash` from `PATH` when available, otherwise `/bin/bash` (important on Windows Git Bash). Anything else runs under the current Python interpreter (`sys.executable`). Scripts must resolve inside `$HERMES_HOME/scripts/` — relative names, absolute paths, and `~`-prefixed paths are accepted when the resolved target stays in that directory; paths that escape it are rejected. Subprocess env is sanitized (`_sanitize_subprocess_env`): provider API credentials and other Hermes-managed secrets are **not** inherited by cron scripts.
+#### Giving a script a credential
+
+A script that must authenticate to an external service (an API token, a service-account key) gets it the same way terminal and `execute_code` children do — declare the variable name in the owning profile's `config.yaml` and define the value in that profile's `.env` (or an external [secret source](/user-guide/secrets/)):
+
+```yaml
+terminal:
+ env_passthrough:
+ - MY_SERVICE_TOKEN
+```
+
+The variable is forwarded into the script's environment with the **owning profile's** value: for a job that belongs to a profile served by a multi-profile gateway or the Desktop/dashboard backend, the value is resolved through that profile's secret scope, never the launch profile's process environment, and that profile's own `.env` credentials never reach another profile's scripts. Hermes-managed provider credentials (`OPENAI_API_KEY`, gateway tokens, …) cannot be declared — the sanitizer rejects them. On a single-profile install the script inherits what the gateway's `.env` put in the process environment, as before. Log presence (`set`/`MISSING`), never the value: script output is delivered verbatim.
+
### The agent sets these up for you
The `cronjob` tool's schema exposes `no_agent` to Hermes directly, so you can describe a watchdog in chat and let the agent wire it up:
diff --git a/website/docs/user-guide/secrets/index.md b/website/docs/user-guide/secrets/index.md
index 29c7df9e94e..6c40c5fbea2 100644
--- a/website/docs/user-guide/secrets/index.md
+++ b/website/docs/user-guide/secrets/index.md
@@ -43,6 +43,10 @@ Two orchestrator-level knobs make one shared vault safe across [profiles](../pro
Both apply to every source — bundled and plugin — because they live in the orchestrator, not the backends.
+## Secrets in child processes
+
+Terminal commands, `execute_code` sandboxes and [`no_agent` cron scripts](/user-guide/features/cron#giving-a-script-a-credential) run with a sanitized environment: Hermes-managed credentials are stripped, and only variables you declare in `terminal.env_passthrough` (or a loaded skill's `required_environment_variables`) are forwarded. A declared variable is forwarded with the **owning profile's** value — from that profile's `.env` or its secret sources — even when the profile is served by a multi-profile gateway or the Desktop/dashboard backend and its secrets never entered the process environment. A profile's declared value never reaches another profile's children, and the launch profile's `.env` credentials are dropped from children that run for a served profile. Provider credentials cannot be declared; see [Security → Credential scoping](/user-guide/security).
+
## Adding your own backend
Third-party secret managers ship as standalone plugins, not core PRs. A backend subclasses `agent.secret_sources.base.SecretSource` (one required method: `fetch(cfg, home_path) -> FetchResult`) and registers via `ctx.register_secret_source(MySource())` in the plugin's `register(ctx)`. The orchestrator owns precedence, conflict handling, timeouts, and provenance — your source only fetches. Full guide with the contract rules, subprocess-safety helper, and conformance kit: [Building a Secret Source Plugin](/developer-guide/secret-source-plugin).
diff --git a/website/docs/user-guide/security.md b/website/docs/user-guide/security.md
index a4ecad4e78d..b696afeb4d3 100644
--- a/website/docs/user-guide/security.md
+++ b/website/docs/user-guide/security.md
@@ -620,6 +620,8 @@ terminal:
- ANOTHER_TOKEN
```
+Both lists apply to `terminal`, `execute_code` and `no_agent` cron scripts alike. A declared variable is forwarded with the value of the profile the child runs for: when one process serves several profiles (multi-profile gateway, Desktop/dashboard backend) each profile's declared value comes from its own `.env` / secret sources, never from the process environment the launch profile populated, and the launch profile's `.env` credentials are dropped from a served profile's children.
+
### Credential File Passthrough (OAuth tokens, etc.) {#credential-file-passthrough}
Some skills need **files** (not just env vars) in the sandbox — for example, Google Workspace stores OAuth tokens as `google_token.json` under the active profile's `HERMES_HOME`. Skills declare these in frontmatter: