Skip to content

cmd: Use $TOOLBOX_DEFAULT_CONTAINER to populate --container#1774

Open
whot wants to merge 1 commit intocontainers:mainfrom
whot:wip/default-container
Open

cmd: Use $TOOLBOX_DEFAULT_CONTAINER to populate --container#1774
whot wants to merge 1 commit intocontainers:mainfrom
whot:wip/default-container

Conversation

@whot
Copy link

@whot whot commented Mar 20, 2026

If set, use the TOOLBOX_DEFAULT_CONTAINER environment variable in lieu of the --container argument. This allows for much easier scripting with partially interactive use-cases.

For example, a user may have different toolboxes for different projects. With this patch one can use e.g. direnv to export the variable, allowing for workflows like this:

   $ cd path/to/myrepo
   # direnv sets TOOLBOX_DEFAULT_CONTAINER to myrepo
   $ toolbox run meson compile -C build
   # expands to --container=myrepo

I've scripted around this locally but it seems like a nice feature to have. I have loads of different containers with the per-project specific builddeps etc so I constantly have to do "toolbox enter foo", "toolbox run --container=bar", etc.

I now have a .use-toolbox file with the container name and my ninja/meson wrappers read this so they auto-execute as toolbox run --container=$(cat .use-toolbox) $@. This works fine, but it's a local bespoke script which would be much nicer to have as built-in functionality.

@whot whot requested a review from debarshiray as a code owner March 20, 2026 04:25
@gemini-code-assist
Copy link

Summary of Changes

Hello, 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 toolbox command-line utility by integrating the TOOLBOX_DEFAULT_CONTAINER environment variable. This allows users to implicitly specify a default container for create, enter, and run operations, streamlining workflows, especially for project-specific container usage. The change aims to reduce repetitive --container flag usage, making scripting and interactive sessions more efficient.

Highlights

  • Default Container from Environment: The --container flag for create, enter, and run commands now defaults to the value of the TOOLBOX_DEFAULT_CONTAINER environment variable if it is set.
  • Improved Scripting Workflow: This change enables easier scripting and interactive use by allowing users to define a default container per project using tools like direnv, reducing the need to explicitly pass the --container flag.
  • Environment Variable Whitelisting: The TOOLBOX_DEFAULT_CONTAINER environment variable has been added to the list of allowed environment variables that can be passed through.

🧠 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.

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.

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.

If set, use the TOOLBOX_DEFAULT_CONTAINER environment variable in lieu
of the --container argument. This allows for much easier scripting with
partially interactive use-cases.

For example, a user may have different toolboxes for different projects.
With this patch one can use e.g. direnv to export the variable, allowing
for workflows like this:
   $ cd path/to/myrepo
   # direnv sets TOOLBOX_DEFAULT_CONTAINER to myrepo
   $ toolbox run meson compile -C build
   # expands to --container=myrepo

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
@whot whot force-pushed the wip/default-container branch from 5b278c9 to 1914bd4 Compare March 20, 2026 04:26
Copy link

@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 introduces a convenient feature by allowing the TOOLBOX_DEFAULT_CONTAINER environment variable to specify the default container for create, enter, and run commands. The implementation for reading the environment variable is correct. However, I've identified a potential issue with adding this variable to the list of preserved environment variables, which could lead to unexpected behavior by leaking host configuration into the container. My review includes a specific comment and suggestion to address this concern.

"SHELL",
"SSH_AUTH_SOCK",
"TERM",
"TOOLBOX_DEFAULT_CONTAINER",

Choose a reason for hiding this comment

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

high

Adding TOOLBOX_DEFAULT_CONTAINER to preservedEnvironmentVariables causes it to be passed from the host into containers during toolbox run. This leaks host-side tool configuration into the container's environment, which can lead to unexpected behavior and breaks isolation. For example, a script inside a container might behave differently depending on the host's TOOLBOX_DEFAULT_CONTAINER setting.

To avoid this, please remove this variable from the list. The main feature of this PR (using the variable on the host) will still work correctly.

Copy link
Author

Choose a reason for hiding this comment

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

Going to wait for human confirmation of this because if the above is correct, I misunderstood it completely :) in my testing this was needed to get a toolbox foo to run correctly when running within a toolbox itself.

@softwarefactory-project-zuul
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant