Skip to content

fix(terminal): strip PYTHONHOME/PYTHONPATH from subprocess env - #24928

Closed
carterwayneskhizeine wants to merge 1 commit into
NousResearch:mainfrom
carterwayneskhizeine:fix-conda
Closed

fix(terminal): strip PYTHONHOME/PYTHONPATH from subprocess env#24928
carterwayneskhizeine wants to merge 1 commit into
NousResearch:mainfrom
carterwayneskhizeine:fix-conda

Conversation

@carterwayneskhizeine

Copy link
Copy Markdown

Summary

On Windows, Hermes Agent bootstraps its own Python via uv and sets PYTHONHOME in the process environment. When the terminal tool spawns subprocesses, this PYTHONHOME is inherited, causing conda (and potentially other Python-based tools) to load uv's Python instead of the system/conda Python — resulting in No module named conda.

Fix

Strip PYTHONHOME and PYTHONPATH from the subprocess environment in _make_run_env(). This mirrors the unset PYTHONHOME / unset PYTHONPATH logic already present in install.sh at launch time.

run_env.pop("PYTHONHOME", None)
run_env.pop("PYTHONPATH", None)

Testing

After patching, conda --version returns conda 25.5.1 correctly in the Hermes Agent terminal session on Windows.

Checklist

  • Tests pass (if applicable)
  • Documentation updated (if applicable)
  • scripts/install.sh Python-path sanitization is already in place

Prevent Hermes Agent's own PYTHONHOME (pointing to uv's Python) from
leaking into terminal subprocesses. This fixes 'No module named conda'
errors on Windows where conda's Scripts/conda-script.py loads the
wrong interpreter.

Cf. install.sh which already unsets these vars at launch time.
@alt-glitch alt-glitch added type/bug Something isn't working tool/terminal Terminal execution and process management backend/local Local shell execution P2 Medium — degraded but workaround exists labels May 13, 2026

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for identifying the inherited Python-runtime environment hazard. The foreground fix needs a small salvage for the current terminal architecture.

Problems

  • The proposed change only covers foreground LocalEnvironment._run_bash, which builds _make_run_env() at tools/environments/local.py:1004. Background and PTY terminal spawns instead call _sanitize_subprocess_env() at tools/process_registry.py:718 and tools/process_registry.py:760; that helper currently copies allowed variables at tools/environments/local.py:355-361 and removes only VIRTUAL_ENV/CONDA_PREFIX at :383-384.
  • The diff contains no regression test. tests/tools/test_local_env_blocklist.py:289-304 already provides the matching pattern of asserting stripping from both environment constructors.

Suggested changes

  • Apply the Python-runtime-variable scrub to both terminal environment builders and add tests for foreground plus background/PTY construction.

Automated hermes-sweeper review.

# Sanitize PYTHONHOME/PYTHONPATH — they can cause the subprocess to load
# the wrong Python interpreter (e.g. uv's Python instead of conda's), which
# breaks tools like conda that rely on finding their own stdlib packages.
run_env.pop("PYTHONHOME", None)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please apply the same scrub to _sanitize_subprocess_env: background and PTY terminal calls use it at tools/process_registry.py:718 and :760, while this change protects only the foreground _make_run_env path.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 13, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Partial update: the PYTHONPATH half of this is now fixed on main via #88182 (selective strip of Hermes-owned entries from all subprocess env builders, preserving user-set paths). The PYTHONHOME half is NOT yet covered on main — that's in scope for the consolidation under review in #82581. Leaving this open until PYTHONHOME stripping lands; if #82581 covers it, this will be closed with credit then.

@teknium1

Copy link
Copy Markdown
Contributor

Both halves of this PR are now fixed on main: the PYTHONPATH strip landed in #88182, and the PYTHONHOME strip — which you were the first to report and propose, back in May — landed today in #88285 (as part of the ownership-model consolidation from #82581). The merged approach strips both selectively rather than the blanket pop proposed here, so user-set entries survive, but your conda repro was the original driver for the PYTHONHOME half. Thank you @carterwayneskhizeine — closing as completed on main.

@teknium1 teknium1 closed this Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend/local Local shell execution P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows tool/terminal Terminal execution and process management type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants