Skip to content

feat(cli): add native gVisor (runsc) sandboxing support#21062

Merged
scidomino merged 9 commits intogoogle-gemini:mainfrom
Zheyuan-Lin:feat/gvisor
Mar 5, 2026
Merged

feat(cli): add native gVisor (runsc) sandboxing support#21062
scidomino merged 9 commits intogoogle-gemini:mainfrom
Zheyuan-Lin:feat/gvisor

Conversation

@Zheyuan-Lin
Copy link
Contributor

@Zheyuan-Lin Zheyuan-Lin commented Mar 4, 2026

Summary

This PR adds native support for gVisor (via runsc) as a sandboxing provider. Users on Linux can run Gemini CLI with stronger process isolation by leveraging gVisor's user-space kernel.
runsc is not auto-detected—it must be explicitly set (e.g. GEMINI_SANDBOX=runsc or sandbox: "runsc"). If you currently use Docker with custom args such as SANDBOX_FLAGS="--runtime=runsc", consider switching to the native runsc support instead.

Details

  • Core type: Added runsc to the SandboxConfig command type union and VALID_SANDBOX_COMMANDS.
  • Native support: When sandbox: "runsc" is set, the CLI runs docker run --runtime=runsc ...; no auto-detection—runsc is used only when explicitly configured.
  • Runtime integration: Linux-only check at sandbox start; container command is derived from config while preserving config.command for env propagation.
  • User reminder: When SANDBOX_FLAGS contains --runtime=runsc but the sandbox command is plain docker, the CLI logs a tip to use native runsc upport (sandbox: "runsc") instead.
  • Documentation: Updated docs/cli/sandbox.md (setup, prerequisites, install/configure/verify) and README to state that runsc is not auto-detected.
  • Tests: Added unit tests in packages/cli/src/config/sandboxConfig.test.ts and packages/cli/src/utils/sandbox.test.ts.

Related Issues

Fixes #15875

How to Validate

  1. Build: npm run build
  2. Sandbox tests:
    npx vitest run packages/cli/src/config/sandboxConfig.test.ts packages/cli/src/utils/sandbox.test.ts (or npm test -w @google/gemini-cli -- src/config/sandboxConfig.test.ts src/utils/sandbox.test.ts)
  3. On Linux (with gVisor installed):
    • Run GEMINI_SANDBOX=runsc gemini "your prompt".
    • Confirm the CLI uses gVisor (e.g. debug logs show sandbox with
      --runtime=runsc in the spawn args).

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • macOS (npm run, npx, Docker, Podman, Seatbelt)
    • Windows (npm run, npx, Docker)
    • Linux (npm run, npx, Docker; runsc logic requires a Linux host)

- Add 'runsc' to the list of valid sandbox commands.
- Implement 'runsc' logic in 'start_sandbox', using 'docker run --runtime=runsc'.
- Add Linux-only platform checks for 'runsc' execution.
- Add validation for 'runsc' and 'docker' binaries when 'runsc' is selected.
- Provide a tip for users using '--runtime=runsc' via 'SANDBOX_FLAGS'.
- Update documentation and add unit tests for configuration and execution.

Co-authored-by: Kartik Angiras <angiraskartik@gmail.com>
@Zheyuan-Lin Zheyuan-Lin requested review from a team as code owners March 4, 2026 05:07
@google-cla
Copy link

google-cla bot commented Mar 4, 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
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 introduces native support for gVisor (runsc) as a sandboxing option within the Gemini CLI, enhancing process isolation for Linux users. By explicitly configuring runsc, users can leverage gVisor's user-space kernel for a more secure execution environment. The changes include core type updates, robust validation for platform and binary availability, and integration with Docker to utilize the runsc runtime. This feature provides a more streamlined and validated approach for gVisor users compared to manual configuration via SANDBOX_FLAGS.

Highlights

  • Native gVisor (runsc) Sandboxing: Added native support for gVisor (runsc) as a sandboxing provider, offering stronger process isolation for Gemini CLI on Linux.
  • Explicit Configuration: Implemented explicit configuration for runsc via GEMINI_SANDBOX=runsc or sandbox: "runsc", as it is not auto-detected.
  • Docker Integration: Integrated runsc by internally executing docker run --runtime=runsc ... when specified.
  • Validation Checks: Introduced validation checks to ensure runsc is used only on Linux and that both runsc and docker binaries are present.
  • User Guidance: Provided a user tip in debug logs for those using SANDBOX_FLAGS="--runtime=runsc" with the docker sandbox command, suggesting a switch to native runsc support.
  • Documentation and Tests: Updated documentation (docs/cli/sandbox.md) to include setup, prerequisites, and usage instructions for gVisor, and added comprehensive unit tests for runsc specific logic.
Changelog
  • docs/cli/sandbox.md
    • Added a new section detailing gVisor/runsc sandboxing, including its benefits, prerequisites, and setup instructions.
    • Updated the GEMINI_SANDBOX environment variable options to include runsc.
  • packages/cli/src/config/sandboxConfig.test.ts
    • Expanded sandbox command validation error messages to include runsc.
    • Added a new test suite for runsc sandboxing, covering configuration loading via CLI, environment variables, and settings files.
    • Included tests for platform-specific rejections (macOS, Windows) and missing binary errors (runsc or docker).
    • Verified that runsc is not auto-detected when sandbox: true.
  • packages/cli/src/config/sandboxConfig.ts
    • Added runsc to the VALID_SANDBOX_COMMANDS array.
    • Implemented logic to check if runsc is selected on a Linux platform and if both runsc and docker binaries are available.
    • Modified the sandbox command detection to explicitly handle runsc and prevent its auto-detection.
  • packages/cli/src/utils/sandbox.test.ts
    • Added tests to confirm that start_sandbox correctly uses docker with --runtime=runsc when runsc is configured.
    • Included tests for FatalSandboxError when runsc is attempted on non-Linux platforms.
    • Added a test to verify the debug log tip is displayed when SANDBOX_FLAGS contains --runtime=runsc with the docker command.
  • packages/cli/src/utils/sandbox.ts
    • Introduced a command variable to resolve the actual executable (docker for runsc) for sandbox operations.
    • Added a platform check for runsc at the start of the start_sandbox function.
    • Modified ensureSandboxImageIsPresent and other execSync/spawn calls to use the resolved command.
    • Injected --runtime=runsc into Docker arguments when config.command is runsc.
    • Implemented a debug logger tip for users who specify --runtime=runsc in SANDBOX_FLAGS while using the docker sandbox command.
  • packages/core/src/config/config.ts
    • Updated the SandboxConfig interface to include runsc as a valid type for the command property.
Activity
  • The pull request was created by Zheyuan-Lin.
  • No additional review comments or activity have been recorded yet.
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.

Copy link
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 introduces native support for gVisor (runsc) sandboxing, which is a great enhancement for security on Linux systems. However, it contains a high-severity command injection vulnerability in the proxy container startup logic due to unsanitized string concatenation in a shell command, which should be addressed by using array-based argument passing for process spawning. Additionally, there is a suggestion to address code duplication in validation logic for improved maintainability, which is supported by the rule regarding trusting internally managed configurations.

@gemini-cli gemini-cli bot added priority/p2 Important but can be addressed in a future release. area/platform Issues related to Build infra, Release mgmt, Testing, Eval infra, Capacity, Quota mgmt help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Mar 4, 2026
Zheyuan added 2 commits March 4, 2026 00:33
…pport

- Refactor proxy container command to use structured argument array and disable shell execution to prevent command injection.
- Remove redundant platform check for runsc in sandbox.ts (handled in config).
- Update and clean up corresponding unit tests.
Resolved conflicts to include both gVisor (runsc) and LXC sandboxing:
- Added both 'runsc' and 'lxc' to valid sandbox commands
- Updated SandboxConfig type to support both options
- Combined sandbox.ts logic to handle both lxc and runsc paths
- Merged documentation sections for both sandbox types
- Updated test expectations to include both commands
@Zheyuan-Lin
Copy link
Contributor Author

@scidomino PTAL

@scidomino scidomino self-requested a review March 4, 2026 21:16
@scidomino
Copy link
Collaborator

This may take a while since I've never set up gvisor on my machine before.

@scidomino
Copy link
Collaborator

Thanks for the PR adding native gVisor sandboxing support! It looks great overall, especially the secure refactor of the proxy container spawn logic to use shell: false and an array of arguments—that's a fantastic improvement against command injection.

I have a couple of minor suggestions before we merge:

  1. Remove the Migration Tip: The debugLogger is primarily for internal debugging (unless GEMINI_DEBUG=true is set), so normal users won't see the tip you added for migrating from SANDBOX_FLAGS=--runtime=runsc to sandbox: "runsc". I suggest removing this tip and the associated check entirely, as it adds a bit of complexity for a message that won't reach most users.

  2. Redundant String Check (If kept): If you do decide to keep the tip (perhaps moving it to a user-facing output), note that the check f === '--runtime=runsc' || f.startsWith('--runtime=runsc') is slightly redundant, as startsWith already covers the exact match case.

Other than that, the platform checks, binary requirements, and test coverage look excellent. Please let me know if you have any questions!

@Zheyuan-Lin
Copy link
Contributor Author

Hi @scidomino, thanks for the review! Removed the migration tip and relevant test cases. PTAL!

@scidomino scidomino enabled auto-merge March 5, 2026 18:15
@scidomino scidomino added this pull request to the merge queue Mar 5, 2026
Merged via the queue into google-gemini:main with commit 2916396 Mar 5, 2026
26 of 27 checks passed
@dtometzki
Copy link
Contributor

hello together,

but the main issue sandbox in vscode terminal doesnt work with runsc too. What i do wrong ?
image

@Zheyuan-Lin
Copy link
Contributor Author

Hi @dtometzki, thanks for raising this!

You're not doing anything wrong — this is a known limitation when using GEMINI_SANDBOX=runsc. gVisor's network isolation prevents the IDE companion from establishing its TCP connection to the host, so the disconnection is expected behavior rather than a misconfiguration.

Recommended fix: Switch to Docker when you need IDE integration

Also worth noting — the error message you're seeing is unfortunately misleading. It's not an issue with your extension setup, but rather a known incompatibility between gVisor's network stack and the IDE connection mechanism. We should improve that message to make this clearer.

struckoff pushed a commit to struckoff/gemini-cli that referenced this pull request Mar 6, 2026
…i#21062)

Co-authored-by: Zheyuan <zlin252@emory.edu>
Co-authored-by: Kartik Angiras <angiraskartik@gmail.com>
kunal-10-cloud pushed a commit to kunal-10-cloud/gemini-cli that referenced this pull request Mar 12, 2026
…i#21062)

Co-authored-by: Zheyuan <zlin252@emory.edu>
Co-authored-by: Kartik Angiras <angiraskartik@gmail.com>
liamhelmer pushed a commit to badal-io/gemini-cli that referenced this pull request Mar 12, 2026
…i#21062)

Co-authored-by: Zheyuan <zlin252@emory.edu>
Co-authored-by: Kartik Angiras <angiraskartik@gmail.com>
yashodipmore pushed a commit to yashodipmore/geemi-cli that referenced this pull request Mar 21, 2026
…i#21062)

Co-authored-by: Zheyuan <zlin252@emory.edu>
Co-authored-by: Kartik Angiras <angiraskartik@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/platform Issues related to Build infra, Release mgmt, Testing, Eval infra, Capacity, Quota mgmt help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p2 Important but can be addressed in a future release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GEMINI_SANDBOX=GVISOR: enable sandboxing via gVisor

3 participants