fix: use BASH_ENV for non-interactive shell config loading #11

Merged
brad merged 2 commits from fix/bash-env-for-agent-config into main 2026-02-13 17:18:48 -08:00
Owner

Problem

Agent environment variables from AGENTS.md were not being loaded for non-interactive shell commands (bash -c).

Root Cause

/etc/bash.bashrc has a guard that exits early for non-interactive shells:

[ -z "$PS1" ] && return

The previous fix appended config sourcing to the bottom of bash.bashrc — after this guard — so it never ran for bash -c commands.

Solution

Use BASH_ENV — the standard environment variable that bash reads for non-interactive shell scripts. This replaces the 5-line bash.bashrc hack with a single ENV directive.

Testing

Verified with the current image + env override:

# Before (fails)
docker run --rm -v ~/.openclaw/workspace:/workspace:ro \
  git.brads.house/commune/sandbox:latest \
  bash -c 'echo FORGEJO_USER=$FORGEJO_USER'
# Output: FORGEJO_USER=

# After (works)
docker run --rm -v ~/.openclaw/workspace:/workspace:ro \
  -e BASH_ENV=/etc/profile.d/agent-config.sh \
  git.brads.house/commune/sandbox:latest \
  bash -c 'echo FORGEJO_USER=$FORGEJO_USER'
# Output: FORGEJO_USER=agent
## Problem Agent environment variables from AGENTS.md were not being loaded for non-interactive shell commands (`bash -c`). ## Root Cause `/etc/bash.bashrc` has a guard that exits early for non-interactive shells: ```bash [ -z "$PS1" ] && return ``` The previous fix appended config sourcing to the *bottom* of bash.bashrc — after this guard — so it never ran for `bash -c` commands. ## Solution Use `BASH_ENV` — the standard environment variable that bash reads for non-interactive shell scripts. This replaces the 5-line bash.bashrc hack with a single `ENV` directive. ## Testing Verified with the current image + env override: ```bash # Before (fails) docker run --rm -v ~/.openclaw/workspace:/workspace:ro \ git.brads.house/commune/sandbox:latest \ bash -c 'echo FORGEJO_USER=$FORGEJO_USER' # Output: FORGEJO_USER= # After (works) docker run --rm -v ~/.openclaw/workspace:/workspace:ro \ -e BASH_ENV=/etc/profile.d/agent-config.sh \ git.brads.house/commune/sandbox:latest \ bash -c 'echo FORGEJO_USER=$FORGEJO_USER' # Output: FORGEJO_USER=agent ```
The previous approach appended config sourcing to /etc/bash.bashrc, but
bash.bashrc has a guard that exits early for non-interactive shells:
  [ -z "$PS1" ] && return

This meant 'bash -c' commands (like OpenClaw exec) never loaded the
agent config from AGENTS.md.

BASH_ENV is the standard way to source config for non-interactive bash
shells. This replaces the bash.bashrc hack with a single ENV directive.
brad merged commit 4b0f32d7e8 into main 2026-02-13 17:18:48 -08:00
brad deleted branch fix/bash-env-for-agent-config 2026-02-13 17:18:48 -08:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
commune/sandbox!11
No description provided.