Skip to content

Support execute_shell_command for env var support#18390

Merged
Fridge003 merged 3 commits intomainfrom
docs-env-args
Feb 7, 2026
Merged

Support execute_shell_command for env var support#18390
Fridge003 merged 3 commits intomainfrom
docs-env-args

Conversation

@zhaochenyang20
Copy link
Copy Markdown
Collaborator

@zhaochenyang20 zhaochenyang20 commented Feb 7, 2026

  1. Enhance execute_shell_command to support environment variable assignments in command strings. -> Fix this: https://github.com/sgl-project/sglang/actions/runs/21769074765/job/62812303842#step:5:201

@b8zhong

  1. Adding tags to execute docs CI. After adding the label, the notebook will be captured.

Motivation

Modifications

Accuracy Tests

Benchmarking and Profiling

Checklist

Review Process

  1. Ping Merge Oncalls to start the PR flow. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • /tag-run-ci-label, /rerun-failed-ci, /tag-and-rerun-ci
  4. After green CI and required approvals, ask Merge Oncalls to merge.

Enhance execute_shell_command to support environment variable assignments in command strings.
@zhaochenyang20
Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @zhaochenyang20, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the execute_shell_command utility to provide more flexible command execution. By integrating support for environment variable assignments directly into the command string, it simplifies the process of running scripts or programs with specific environment configurations, particularly useful in notebook or CI environments, without relying on less secure shell execution.

Highlights

  • Environment Variable Support: The execute_shell_command utility function now supports parsing and applying leading KEY=VALUE environment variable assignments directly within the command string. This allows for setting environment variables for a command without needing to use shell=True in subprocess.Popen.
  • Robust Command Parsing: The function includes logic to identify valid environment variable assignments, ensuring they are at the beginning of the command and follow a KEY=VALUE format, while also handling cases where the command might only consist of environment variables, raising a ValueError.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • python/sglang/utils.py
    • Modified execute_shell_command to parse and apply leading KEY=VALUE environment variable assignments from the input command string.
    • Updated the function's docstring to reflect the new environment variable support.
    • Implemented a loop to extract environment variables, copying the current process's environment and updating it with new assignments.
    • Added validation to ensure extracted parts are valid environment variable assignments (e.g., not starting with '-' or '/').
    • Introduced a ValueError if the command string consists solely of environment variable assignments without an executable.
    • Passed the constructed environment dictionary (env) to subprocess.Popen.
Activity
  • The pull request was created by zhaochenyang20 with the title "Support execute_shell_command for env var support" and a description outlining the motivation and modification details.
  • The author provided a checklist for code quality, testing, documentation, and benchmarking, indicating the standard process for contributions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions github-actions Bot added the run-ci label Feb 7, 2026
@zhaochenyang20
Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enhances execute_shell_command to support environment variables in the command string, which is a great improvement to avoid using shell=True.

I've found a few areas where the parsing logic could be more robust. My main suggestion is to use shlex.split() for command parsing to correctly handle quoted arguments, and to simplify the environment variable validation using isidentifier(). This will make the function more reliable with a wider range of command strings.

Comment thread python/sglang/utils.py
@zhaochenyang20
Copy link
Copy Markdown
Collaborator Author

The document CI has been fixed. Thanks!

https://github.com/sgl-project/sglang/actions/runs/21773786824/job/62826353543

Please merge this

@Fridge003 Fridge003 merged commit 1552aab into main Feb 7, 2026
36 of 49 checks passed
@Fridge003 Fridge003 deleted the docs-env-args branch February 7, 2026 04:33
charlesHsuGG pushed a commit to charlesHsuGG/sglang that referenced this pull request Feb 9, 2026
Johnsonms pushed a commit to Johnsonms/sglang that referenced this pull request Feb 14, 2026
magicYang1573 pushed a commit to magicYang1573/sglang that referenced this pull request Mar 9, 2026
Wangzheee pushed a commit to Wangzheee/sglang that referenced this pull request Mar 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants