forked from NousResearch/hermes-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Sanitize subprocess environments in tools_config.py #703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
badMade
wants to merge
2
commits into
main
Choose a base branch
from
sanitize-tools-config-env-6334960680090751462
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -567,6 +567,7 @@ def _pip_install( | |
| timeout: int = 300, | ||
| capture_output: bool = True, | ||
| ): | ||
| from tools.environments.local import _sanitize_subprocess_env | ||
| """Install Python packages from a post-setup hook. | ||
|
|
||
| Strategy (in order): | ||
|
|
@@ -584,7 +585,7 @@ def _pip_install( | |
| (or the last failure for the caller to inspect). | ||
| """ | ||
| venv_root = Path(sys.executable).parent.parent | ||
| uv_env = {**os.environ, "VIRTUAL_ENV": str(venv_root)} | ||
| uv_env = _sanitize_subprocess_env(os.environ.copy(), {"VIRTUAL_ENV": str(venv_root)}) | ||
|
|
||
| uv_bin = shutil.which("uv") | ||
| if uv_bin: | ||
|
|
@@ -607,6 +608,7 @@ def _pip_install( | |
| probe = subprocess.run( | ||
| pip_cmd + ["--version"], | ||
| capture_output=True, text=True, timeout=15, | ||
| env=_sanitize_subprocess_env(os.environ.copy()), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ) | ||
| if probe.returncode != 0: | ||
| raise FileNotFoundError("pip not in venv") | ||
|
|
@@ -615,6 +617,7 @@ def _pip_install( | |
| subprocess.run( | ||
| [sys.executable, "-m", "ensurepip", "--upgrade", "--default-pip"], | ||
| capture_output=True, text=True, timeout=120, check=True, | ||
| env=_sanitize_subprocess_env(os.environ.copy()), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ) | ||
| except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as e: | ||
| # Synthesize a result so callers see a clean failure path. | ||
|
|
@@ -626,12 +629,14 @@ def _pip_install( | |
| return subprocess.run( | ||
| pip_cmd + ["install", *args], | ||
| capture_output=capture_output, text=True, timeout=timeout, | ||
| env=_sanitize_subprocess_env(os.environ.copy()), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ) | ||
|
|
||
|
|
||
| def _run_post_setup(post_setup_key: str): | ||
| """Run post-setup hooks for tools that need extra installation steps.""" | ||
| import shutil | ||
| from tools.environments.local import _sanitize_subprocess_env | ||
| if post_setup_key in {"agent_browser", "browserbase"}: | ||
| node_modules = PROJECT_ROOT / "node_modules" / "agent-browser" | ||
| npm_bin = shutil.which("npm") | ||
|
|
@@ -646,7 +651,8 @@ def _run_post_setup(post_setup_key: str): | |
| # behaviour as before. | ||
| result = subprocess.run( | ||
| [npm_bin, "install", "--silent"], | ||
| capture_output=True, text=True, cwd=str(PROJECT_ROOT) | ||
| capture_output=True, text=True, cwd=str(PROJECT_ROOT), | ||
| env=_sanitize_subprocess_env(os.environ.copy()), | ||
| ) | ||
| if result.returncode == 0: | ||
| _print_success(" Node.js dependencies installed") | ||
|
|
@@ -722,6 +728,7 @@ def _run_post_setup(post_setup_key: str): | |
| result = subprocess.run( | ||
| install_cmd, | ||
| capture_output=True, text=True, cwd=str(PROJECT_ROOT), timeout=600, | ||
| env=_sanitize_subprocess_env(os.environ.copy()), | ||
| ) | ||
| if result.returncode == 0: | ||
| _print_success(" Chromium installed") | ||
|
|
@@ -751,7 +758,8 @@ def _run_post_setup(post_setup_key: str): | |
| # Absolute npm path so .cmd shim executes on Windows. | ||
| result = subprocess.run( | ||
| [_npm_bin, "install", "--silent"], | ||
| capture_output=True, text=True, cwd=str(PROJECT_ROOT) | ||
| capture_output=True, text=True, cwd=str(PROJECT_ROOT), | ||
| env=_sanitize_subprocess_env(os.environ.copy()), | ||
| ) | ||
| if result.returncode == 0: | ||
| _print_success(" Camofox installed") | ||
|
|
@@ -779,6 +787,7 @@ def _run_post_setup(post_setup_key: str): | |
| version = subprocess.run( | ||
| ["cua-driver", "--version"], | ||
| capture_output=True, text=True, timeout=5, | ||
| env=_sanitize_subprocess_env(os.environ.copy()), | ||
| ).stdout.strip() | ||
| _print_success(f" cua-driver already installed: {version or 'unknown version'}") | ||
| except Exception: | ||
|
|
@@ -798,7 +807,12 @@ def _run_post_setup(post_setup_key: str): | |
| "https://raw.githubusercontent.com/trycua/cua/main/" | ||
| "libs/cua-driver/scripts/install.sh)\"" | ||
| ) | ||
| result = subprocess.run(install_cmd, shell=True, timeout=300) | ||
| result = subprocess.run( | ||
| install_cmd, | ||
| shell=True, | ||
| timeout=300, | ||
| env=_sanitize_subprocess_env(os.environ.copy()), | ||
| ) | ||
| if result.returncode == 0 and shutil.which("cua-driver"): | ||
| _print_success(" cua-driver installed.") | ||
| _print_info(" IMPORTANT — grant macOS permissions now:") | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of calling
_sanitize_subprocess_env(os.environ.copy())multiple times throughout_pip_install, we can sanitize the environment once at the beginning of the function and reuse it. This avoids redundant environment copying and blocklist filtering overhead.