Repository navigation
fix(cli): persist sandbox authentication and sessions - #29671
BLVCK-MAMBA-6 wants to merge 2 commits into
Conversation
|
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. |
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 persistent state management for the Gemini CLI sandbox environment. By enabling the retention of authentication, folder-trust, and session data, it resolves issues related to repeated prompts and lost sessions while maintaining strict security boundaries between the host environment and the isolated sandbox container. Highlights
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 the 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 counterproductive. 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
|
|
📊 PR Size: size/L
|
There was a problem hiding this comment.
Code Review
This pull request implements sandbox state persistence and restoration between sandbox invocations, ensuring that sandbox-created state (such as credentials, history, and trusted folders) is safely preserved while remaining isolated from host credentials. The review feedback highlights an issue where fs.chmodSync could throw permission errors on non-POSIX filesystems and abort state persistence, suggesting wrapping it in a try-catch block. Additionally, the feedback points out a style guide violation in the unit tests where process.env is modified directly, recommending the use of vi.stubEnv to prevent test leakage.
| try { | ||
| fs.mkdirSync(sandboxStateDir, { recursive: true, mode: 0o700 }); | ||
| fs.chmodSync(sandboxStateDir, 0o700); | ||
| } catch (err) { | ||
| debugLogger.warn( | ||
| `Failed to prepare persistent sandbox state directory: ${err instanceof Error ? err.message : String(err)}`, | ||
| ); | ||
| return; | ||
| } |
There was a problem hiding this comment.
On non-POSIX filesystems (such as Windows or certain shared mounts), fs.chmodSync can throw permission errors (e.g., EPERM). Aborting the entire persistSandboxState function on chmodSync failure will prevent state persistence entirely in these environments. Instead, wrap fs.chmodSync in its own try-catch block to silently ignore permission errors, similar to how it is handled in sandbox.ts.
try {
fs.mkdirSync(sandboxStateDir, { recursive: true, mode: 0o700 });
try {
fs.chmodSync(sandboxStateDir, 0o700);
} catch {
// Silently ignore permission errors on non-POSIX filesystems
}
} catch (err) {
debugLogger.warn(
`Failed to prepare persistent sandbox state directory: ${err instanceof Error ? err.message : String(err)}`,
);
return;
}| delete process.env['PATH']; | ||
| delete process.env['PYTHONPATH']; |
There was a problem hiding this comment.
According to the repository style guide (Testing Conventions, lines 84-90), modifying process.env directly should be avoided to prevent test leakage. Instead, use vi.stubEnv('NAME', '') to unset environment variables.
| delete process.env['PATH']; | |
| delete process.env['PYTHONPATH']; | |
| vi.stubEnv('PATH', ''); | |
| vi.stubEnv('PYTHONPATH', ''); |
References
- Testing Conventions (lines 84-90) state that when testing code that depends on environment variables, we should use vi.stubEnv('NAME', 'value') in beforeEach and vi.unstubAllEnvs() in afterEach, and avoid modifying process.env directly to prevent test leakage. (link)
| delete process.env['PATH']; | ||
| delete process.env['PYTHONPATH']; |
There was a problem hiding this comment.
According to the repository style guide (Testing Conventions, lines 84-90), modifying process.env directly should be avoided to prevent test leakage. Instead, use vi.stubEnv('NAME', '') to unset environment variables.
| delete process.env['PATH']; | |
| delete process.env['PYTHONPATH']; | |
| vi.stubEnv('PATH', ''); | |
| vi.stubEnv('PYTHONPATH', ''); |
References
- Testing Conventions (lines 84-90) state that when testing code that depends on environment variables, we should use vi.stubEnv('NAME', 'value') in beforeEach and vi.unstubAllEnvs() in afterEach, and avoid modifying process.env directly to prevent test leakage. (link)
Summary
Persist authentication, folder-trust, and session state across sandbox container invocations.
This fixes the repeated authentication prompts, lost sessions, and folder-trust restart loop reported in #29461 while keeping the rest of the host Gemini configuration isolated from the sandbox.
Details
~/.gemini/sandbox.settings.json; hooks, commands, and other host settings remain excluded.Related Issues
Fixes #29461
How to Validate
Run the focused unit tests:
npm test -w @google/gemini-cli -- \ src/utils/sandboxUtils.test.ts \ src/utils/sandbox.test.tsExpected result: all 97 tests pass.
Run ESLint against the changed files:
For a Docker integration test:
gemini --resumeorgemini --list-sessionsand confirm the previous session is available.The local Docker smoke test confirmed that credentials and folder trust were restored without entering the restart loop. A complete live-session interaction was blocked by an unrelated unsupported-nightly-client response, while session persistence paths are covered by the unit tests.
The repository-wide lint command was terminated by the local environment with exit code 143; focused ESLint on all changed files passed.
Pre-Merge Checklist