Skip to content

fix(cli): randomize sandbox container names#26014

Merged
scidomino merged 3 commits intogoogle-gemini:mainfrom
Kkartik14:fix-sandbox-container-name-collisions
May 6, 2026
Merged

fix(cli): randomize sandbox container names#26014
scidomino merged 3 commits intogoogle-gemini:mainfrom
Kkartik14:fix-sandbox-container-name-collisions

Conversation

@Kkartik14
Copy link
Copy Markdown
Contributor

The sequential -N allocator listed existing containers and picked the first unused index, which races when two CLIs start concurrently.

Replace it with a 12-hex random suffix using randomBytes(6), shared by the regular and integration-test branches. Drop the ps -a probe, and keep --name, --hostname, and SANDBOX aligned.

Fixes #12083

The sequential <image>-N allocator listed existing containers and picked the first unused index, which races when two CLIs start concurrently.

Replace it with a 12-hex random suffix using randomBytes(6), shared by the regular and integration-test branches. Drop the ps -a probe, and keep --name, --hostname, and SANDBOX aligned.

Fixes google-gemini#12083
@Kkartik14 Kkartik14 requested a review from a team as a code owner April 26, 2026 20:12
@google-cla
Copy link
Copy Markdown

google-cla Bot commented Apr 26, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

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 addresses a race condition in the CLI sandbox container allocation. By switching from a sequential index-based naming system to a randomized suffix approach, the CLI can now safely handle concurrent starts without attempting to reuse or conflict with existing container names. This change simplifies the container initialization process by removing the need to query the Docker daemon for existing containers before launching a new one.

Highlights

  • Container Naming Strategy: Replaced the sequential container naming logic with a 12-hex random suffix generated via randomBytes(6) to prevent race conditions during concurrent CLI executions.
  • Performance Improvement: Removed the 'ps -a' probe that checked for existing containers, reducing overhead and eliminating potential race conditions.
  • Test Suite Updates: Updated sandbox tests to reflect the new random naming strategy and added verification for the removal of the 'ps -a' command.
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.

@gemini-cli gemini-cli Bot added priority/p3 Backlog - a good idea but not currently a priority. area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Apr 26, 2026
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 refactors the sandbox container naming logic to use a random 6-byte hex suffix instead of probing for sequential indices, preventing race conditions during concurrent CLI starts. The tests in packages/cli/src/utils/sandbox.test.ts were updated to mock node:crypto and verify the new naming behavior for both standard and integration test environments. I have no feedback to provide.

@SHARABUMANOJKUMAR
Copy link
Copy Markdown

Hi, I would like to work on this issue. I have been contributing to Gemini CLI and would love to take this up. Can I proceed?

@SHARABUMANOJKUMAR
Copy link
Copy Markdown

Hi, I would like to work on this issue. Can I proceed?

@Kkartik14
Copy link
Copy Markdown
Contributor Author

Kkartik14 commented Apr 28, 2026

Hey @jacob314 @cocosheng-g whenever you have time, since you were involved in the related issue, would appreciate any feedback on this PR. Happy to iterate on it!

@scidomino scidomino self-requested a review May 4, 2026 20:35
@scidomino scidomino enabled auto-merge May 4, 2026 20:42
@scidomino
Copy link
Copy Markdown
Collaborator

FYI, don't touch the PR or else we have to run the tests all over again.

@Kkartik14
Copy link
Copy Markdown
Contributor Author

Yeah, I realized after updating, really appreciate you taking care of it, thanks!

@Kkartik14
Copy link
Copy Markdown
Contributor Author

Hey @scidomino , the failing Windows checks don't look related to my changes, could you rerun them, or let me know if you'd like me to make any changes?

@scidomino scidomino added this pull request to the merge queue May 6, 2026
Merged via the queue into google-gemini:main with commit 5155221 May 6, 2026
44 of 47 checks passed
@Kkartik14
Copy link
Copy Markdown
Contributor Author

Thanks for the review and merge

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

Labels

area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p3 Backlog - a good idea but not currently a priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Container name collisions due to sequential numbering in container name generation

3 participants