-
Notifications
You must be signed in to change notification settings - Fork 13k
feat(core): implement native Windows sandboxing #21807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1425e94
feat(core): implement native Windows sandboxing with restricted tokens
mattKorwel 7814427
feat(core,cli): harden windows sandboxing and add platform-agnostic t…
mattKorwel d7fb4bf
feat(core): address review comments and fix strict sandbox shell sele…
mattKorwel 4848908
Merge branch 'main' into mk-windows-sandboxing
mattKorwel f08fad9
feat(windows-sandbox): address review comments, fix shell integration…
mattKorwel 2431d75
feat(windows-sandbox): address final async review findings and fix es…
mattKorwel 7268c12
test(core): fix typescript errors in sandboxed filesystem tests
mattKorwel 4dbbb84
feat(windows-sandbox): resolve merge conflicts and apply final polish
mattKorwel 2b66650
feat(windows-sandbox): fix lint errors and type mismatches
mattKorwel 16d91aa
feat(windows-sandbox): architectural hardening, spawnAsync refactor, …
mattKorwel 7fd61ce
style: apply prettier formatting to windows-sandbox related files
mattKorwel a4fe937
chore(windows-sandbox): improve diagnostics and error handling in san…
mattKorwel 4ace82e
chore(windows-sandbox): fix eslint errors in sandboxed file system
mattKorwel c2fb66d
test(windows-sandbox): fix sandboxed file system test mock with prope…
mattKorwel 75f2eee
test(windows-sandbox): fix TS compilation error in tests
mattKorwel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| packages/core/src/services/scripts/*.exe |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| /* eslint-env node */ | ||
|
|
||
| import { spawnSync } from 'node:child_process'; | ||
| import path from 'node:path'; | ||
| import fs from 'node:fs'; | ||
| import os from 'node:os'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = path.dirname(__filename); | ||
|
|
||
| /** | ||
| * Compiles the GeminiSandbox C# helper on Windows. | ||
| * This is used to provide native restricted token sandboxing. | ||
| */ | ||
| function compileWindowsSandbox() { | ||
| if (os.platform() !== 'win32') { | ||
| return; | ||
| } | ||
|
|
||
| const srcHelperPath = path.resolve( | ||
| __dirname, | ||
| '../src/services/scripts/GeminiSandbox.exe', | ||
| ); | ||
| const distHelperPath = path.resolve( | ||
| __dirname, | ||
| '../dist/src/services/scripts/GeminiSandbox.exe', | ||
| ); | ||
| const sourcePath = path.resolve( | ||
| __dirname, | ||
| '../src/services/scripts/GeminiSandbox.cs', | ||
| ); | ||
|
|
||
| if (!fs.existsSync(sourcePath)) { | ||
| console.error(`Sandbox source not found at ${sourcePath}`); | ||
| return; | ||
| } | ||
|
|
||
| // Ensure directories exist | ||
| [srcHelperPath, distHelperPath].forEach((p) => { | ||
| const dir = path.dirname(p); | ||
| if (!fs.existsSync(dir)) { | ||
| fs.mkdirSync(dir, { recursive: true }); | ||
| } | ||
| }); | ||
|
|
||
| // Find csc.exe (C# Compiler) which is built into Windows .NET Framework | ||
| const systemRoot = process.env['SystemRoot'] || 'C:\\Windows'; | ||
| const cscPaths = [ | ||
| 'csc.exe', // Try in PATH first | ||
| path.join( | ||
| systemRoot, | ||
| 'Microsoft.NET', | ||
| 'Framework64', | ||
| 'v4.0.30319', | ||
| 'csc.exe', | ||
| ), | ||
| path.join( | ||
| systemRoot, | ||
| 'Microsoft.NET', | ||
| 'Framework', | ||
| 'v4.0.30319', | ||
| 'csc.exe', | ||
| ), | ||
| ]; | ||
|
|
||
| let csc = undefined; | ||
| for (const p of cscPaths) { | ||
| if (p === 'csc.exe') { | ||
| const result = spawnSync('where', ['csc.exe'], { stdio: 'ignore' }); | ||
| if (result.status === 0) { | ||
| csc = 'csc.exe'; | ||
| break; | ||
| } | ||
| } else if (fs.existsSync(p)) { | ||
| csc = p; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (!csc) { | ||
| console.warn( | ||
| 'Windows C# compiler (csc.exe) not found. Native sandboxing will attempt to compile on first run.', | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| console.log(`Compiling native Windows sandbox helper...`); | ||
| // Compile to src | ||
| let result = spawnSync( | ||
| csc, | ||
| [`/out:${srcHelperPath}`, '/optimize', sourcePath], | ||
| { | ||
| stdio: 'inherit', | ||
| }, | ||
| ); | ||
|
|
||
| if (result.status === 0) { | ||
| console.log('Successfully compiled GeminiSandbox.exe to src'); | ||
| // Copy to dist if dist exists | ||
| const distDir = path.resolve(__dirname, '../dist'); | ||
| if (fs.existsSync(distDir)) { | ||
| const distScriptsDir = path.dirname(distHelperPath); | ||
| if (!fs.existsSync(distScriptsDir)) { | ||
| fs.mkdirSync(distScriptsDir, { recursive: true }); | ||
| } | ||
| fs.copyFileSync(srcHelperPath, distHelperPath); | ||
| console.log('Successfully copied GeminiSandbox.exe to dist'); | ||
| } | ||
| } else { | ||
| console.error('Failed to compile Windows sandbox helper.'); | ||
| } | ||
| } | ||
|
|
||
| compileWindowsSandbox(); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.