feat(sandbox): add experimental LXC container sandbox support#20735
feat(sandbox): add experimental LXC container sandbox support#20735scidomino merged 4 commits intogoogle-gemini:mainfrom
Conversation
Summary of ChangesHello, 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 experimental support for LXC/LXD containers as a sandboxing mechanism within the Gemini CLI. This enhancement addresses the need for full-system container environments, which are crucial for specific tools like Snapcraft and Rockcraft that rely on services like Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces experimental support for LXC/LXD containers as a sandboxing option, which is a great addition for Linux-specific workflows. The implementation follows the existing sandbox pattern, and the changes to configuration, tests, and documentation are thorough. However, I've found a critical command injection vulnerability in the new start_lxc_sandbox function. User-controlled input is used to construct shell commands with execAsync and execSync, which allows for arbitrary command execution. This must be addressed before merging. My review comment provides details on the vulnerability and how to fix it.
|
Hi @scidomino When you’re free, could you please take a look to this PR. No rush thank you very much! 🙏 |
|
@h30s I am no longer reviewing external PRs unless:
|
|
@scidomino I work on this issue but forgot to comment /assign before opening the PR. After submitting it, someone else added the assignment. The issue is tagged with help wanted, and I have addressed all the requirements. This was an honest mistake kindly consider reviewing the PR. |
|
@h30s ok. I will review. Please note that we now support "/unassign" so if the reason you didn't assign yourself is that you had already hit your 3 issue limit, know that this is not an issue anymore. |
|
Thanks for adding this experimental LXC support! The implementation is very well-contained and fits cleanly into the existing sandbox structure. I noticed a few issues around process lifecycle management and documentation that we should address before merging: 1. Memory Leak & Unnecessary Process ListenersIn Additionally, you only need to listen to the Suggestion:
// Remove the workspace device from the container when the process exits.
const removeDevice = () => {
try {
execFileSync('lxc', [
'config',
'device',
'remove',
containerName,
deviceName,
], { timeout: 2000 }); // See point 2
} catch {
// Best-effort cleanup; ignore errors on exit.
}
};
// Only listen on 'exit'
process.on('exit', removeDevice);
// ... later in the close handler ...
sandboxProcess.on('close', (code, signal) => {
process.stdin.resume();
process.off('exit', removeDevice); // Clean up the listener!
removeDevice();
// ...2.
|
|
Thanks for the review @scidomino! I have addressed the feedback by:
All 12 sandbox unit tests are passing! |
|
@h30s broken lint. Please run |
I’ve run |
|
@h30s The error message in the checks about say:
|
Head branch was pushed to by a user without write access
…ema.json Updated the sandbox description in settingsSchema.ts to mention explicit sandbox commands (docker, podman, lxc) and regenerated the JSON schema via 'npm run schema:settings' to fix CI schema validation.
|
@scidomino I’ve regenerated the settings schema and rerun npm run preflight. Everything should be aligned now. PTAL sorry for the inconvenience. |
Head branch was pushed to by a user without write access
Summary
Adds experimental Linux-only LXC/LXD-based sandboxing support to Gemini CLI. This enables tools like Snapcraft and Rockcraft that require a full system container with
systemdandsnapd— services that Docker/Podman cannot provide in standard containers.The user creates and manages their own LXC container; Gemini runs inside it via
lxc exec. The workspace is bind-mounted at the same absolute path. This follows the established sandbox abstraction pattern without requiring a container image.Details
'lxc'to theSandboxConfig.commandunion type inpackages/core'lxc'toVALID_SANDBOX_COMMANDSinsandboxConfig.ts(explicit opt-in only viaGEMINI_SANDBOX=lxcorsandbox: "lxc"in settings — NOT auto-detected because LXC requires a user-managed, pre-running container)start_lxc_sandbox()insandbox.ts:lxc list --format=jsonlxc config device add(idempotent, random device name for parallel safety)--envflags tolxc execconfig.imageto store the container name (default:"gemini-sandbox", overridable viaGEMINI_SANDBOX_IMAGE)docs/cli/sandbox.mdwith a new LXC section covering setup, quick start, and limitationsRelated Issues
Closes #14627
How to Validate
Unit tests (no LXC required):
npm test -w @google/gemini-cli -- src/config/sandboxConfig.test.ts src/utils/sandbox.test.tsManual validation (Linux with LXC/LXD):
Pre-Merge Checklist