By default, run_shell and run_job do not keep a persistent shell
session. They prepare an environment snapshot once per project/profile and
then run each command as an independent process with that snapshot. The
explicit Workflow Session persistent-shell tools described in section 9 are
the only long-lived exception. This page describes how both paths apply shell
profiles and their safety boundaries.
Applies to
webcodex-runner(the host agent that executes shell commands). The server never reads or stores shell env values, init_script bodies, or tokens.
When a command runs for a project, the agent:
- Resolves the effective profile (
project.shell_profile, elseshell.default_profile, else plain shell config). - Prepares a one-time environment snapshot for that
project/cwd + profilepair: it starts the profile program withenv_clear, applies the profileenv, runs the profileinit_script(if any), and captures the resulting environment viaenv -0behind a unique marker. - Caches the snapshot keyed by
project/cwd + profile name. - Runs every subsequent command for that pair as a fresh process with the
cached snapshot applied — there is no long-lived shell, no
sourceper command, and no.bashrc/.profileloaded by default.
Because the snapshot is keyed by project path + profile name, the same profile
can be reused by multiple projects, and a project-relative init_script (e.g.
source .venv/bin/activate) is resolved from each project's own root.
WebCodex intentionally does not source ~/.bashrc or ~/.profile when
preparing a snapshot:
.bashrccan be slow (network calls, prompts, completions).- It may contain interactive-only commands (
stty,echo, prompts) that break non-interactive capture or hang the prepare step. - It can leak or pollute the environment (secrets, aliases, functions).
- It is non-reproducible across hosts and users.
Use an explicit shell profile instead. Explicit profiles are auditable, fast, and do not depend on the interactive shell setup of the agent's user.
[shell]
default_profile = "rust"
[shell.profiles.rust]
program = "sh"
args = ["-c"]
[shell.profiles.rust.env]
PATH = "/root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
CARGO_HOME = "/root/.cargo"
RUSTUP_HOME = "/root/.rustup"This profile needs no init_script: the env block already sets PATH,
CARGO_HOME, and RUSTUP_HOME, so cargo / rustc are directly available.
[shell.profiles.py-venv]
program = "bash"
args = ["-lc"]
init_script = '''
source .venv/bin/activate
'''The init_script is project-relative: .venv/bin/activate is resolved
from the project root, so each project activates its own venv. The snapshot is
captured once per project/profile pair.
[shell.profiles.conda-ml]
program = "bash"
args = ["-lc"]
init_script = '''
source /opt/miniconda3/etc/profile.d/conda.sh
conda activate ml
'''A project TOML (projects.d/<id>.toml) can pin a profile:
id = "paper-exp"
path = "/root/git/paper-exp"
shell_profile = "conda-ml"The effective profile for a command is chosen as:
project.shell_profile(if set), elseshell.default_profile(if set), else- fallback to the plain shell config (no prepared snapshot).
Notes:
- The snapshot cache key is
project/cwd + profile name. - The same profile can be reused by multiple projects.
.venv(and any project-relativeinit_script) is prepared in the project root.listProjectsexposesshell_profile(the project's setting),resolved_shell_profile(the actually-used name), andshell_profile_status(configured/missing/not_configured/unknown).
Runner registration reports shell dialect facts so the server and agents never have to guess the remote shell:
- The shell profiles summary carries
default_dialect(sh|bash|custom) — the dialect of the runner's default shell program — andavailable_dialects, which always containsshandbash, pluscustomwhen custom profiles exist. - Each profile entry carries its own
dialect. - A custom profile whose program does not map to sh or bash reports
custom. Agents that need deterministic command syntax must select an explicit shell instead of relying on the profile dialect. - An explicit
shell=sh|bashonrun_shell/run_jobalways overrides the default; the server never guesses the remote shell. - Dialect reporting is metadata only: no PATH, env values, or
init_scriptcontents are ever sent to the server.
On the full operator runtime, a registered-project-bound Workflow Session can
store an optional project-relative default_cwd and an optional
default_shell (sh or bash). These are execution defaults, not a prepared
environment snapshot or implicit process reuse.
For run_shell, run_job, and open_session_shell, resolution is:
- explicit per-call
cwd/shell; - the exact active project-matched Workflow Session defaults;
- the existing project root / configured shell-profile behavior.
Omitting a Session keeps the existing behavior. A Session from another project
never contributes defaults. Invalid, missing, or outside-root directories fail
through the existing cwd safety checks without silently retrying at the project
root. run_shell and run_job remain independent processes; a command such as
cd sub does not affect later one-shot calls.
start_coding_task(execution_context=...) can set or replace the context.
Omission during continuation preserves it, while {} clears it.
update_session_context performs a full replacement for an explicit active
Workflow Session only after its required project is authorized and resolves to
the exact Session project; cross-project escape is rejected. The context and
event commit together in memory, while the JSON ledger is queued to the
background writer, so success is not a synchronous durability guarantee. The
context cannot store env values, tokens, arbitrary options, or shell state.
open_session_shell is the explicit exception: it creates one real
long-lived sh/bash process for that Workflow Session. The selected profile
environment and initialization execute once at open, so later
session_shell_exec calls retain cwd, exports, functions, umask, and shell
variables. Profile args remain the one-shot command invocation contract and
are not reused for the long-lived process; persistent bash starts with
--noprofile --norc, while persistent sh starts without command-mode
arguments. Updating Session context does not alter an already-open process;
close and reopen it to apply a changed cwd, dialect, or profile default.
Persistent shells are rejected for read_only/inspect Sessions and for a
Session with an SSH resource.
After editing agent.toml, reload the Runner service. A valid hot reload moves
new one-shot commands to a new profile-cache generation, so their snapshots are
prepared lazily again. Project TOML changes are refreshed independently.
An already-open persistent shell is never silently restarted or rewritten by a reload. Current policy and project/profile selection are rechecked before later exec/status operations, but the environment and initialization already inside that process remain unchanged. Explicitly close and reopen it to apply changed profile contents, cwd, or dialect defaults. Configuration fields outside the documented hot-reload boundary still require a Runner restart; see DEPLOYMENT.md.
- Never put tokens in
init_script. - Never
echo/printfsecrets ininit_script— anything the script writes to stdout is parsed as part of the env snapshot capture. - Status /
runtime_status/listAgents/listProjectsexpose only sanitized metadata: profile name,has_init_script(boolean),env_keys_count(count),program,args_count, per-profiledialect, and the summarydefault_dialect/available_dialects. They never exposeinit_scriptbodies, env values, tokens, the Authorization header, the fullagent.toml, or the full env snapshot. - A prepare failure may surface a safe error summary (e.g. "failed to
prepare shell profile 'x' at "), but never the
init_scriptbody or stderr tail. - The WebCodex agent token (
WEBCODEX_TOKEN/WEBCODEX_AGENT_TOKEN/WEBCODEX_USER_TOKEN/AUTHORIZATION) is stripped from the child process environment and is never passed to commands. prepareruns withenv_clear+ an explicit allowlist of inherited keys; profiles must declare the env they need.
For a canonical project, run the shared read-only readiness checks:
webcodex doctorFor an advanced enrolled profile, combine Agent status with operator status:
webcodex agent status \
--profile workstation \
--server-url https://example.test
webcodex ops status \
--server-url https://example.test \
--token-file ~/.config/webcodex/user.token \
--strictProfile preparation failures remain sanitized in Agent status/logs: neither
init_script bodies nor environment values are exposed. Fleet/project
roundtrips belong to explicit operator smoke checks, not ordinary onboarding.
See also:
- AGENT_PROJECTS.md — agent project registry.
- TROUBLESHOOTING.md — operational checklist.
- BUILD_INSTALL.md — install and status reference.