[ide-mode] Wire up env variables to sandbox (#5804)

This commit is contained in:
christine betts 2025-08-08 15:35:47 +00:00 committed by GitHub
parent 407393b128
commit 5ec4ea9b4d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View File

@ -614,6 +614,17 @@ export async function start_sandbox(
args.push('--env', `COLORTERM=${process.env.COLORTERM}`); args.push('--env', `COLORTERM=${process.env.COLORTERM}`);
} }
// Pass through IDE mode environment variables
for (const envVar of [
'GEMINI_CLI_IDE_SERVER_PORT',
'GEMINI_CLI_IDE_WORKSPACE_PATH',
'TERM_PROGRAM',
]) {
if (process.env[envVar]) {
args.push('--env', `${envVar}=${process.env[envVar]}`);
}
}
// copy VIRTUAL_ENV if under working directory // copy VIRTUAL_ENV if under working directory
// also mount-replace VIRTUAL_ENV directory with <project_settings>/sandbox.venv // also mount-replace VIRTUAL_ENV directory with <project_settings>/sandbox.venv
// sandbox can then set up this new VIRTUAL_ENV directory using sandbox.bashrc (see below) // sandbox can then set up this new VIRTUAL_ENV directory using sandbox.bashrc (see below)

View File

@ -324,7 +324,7 @@ export class IdeClient {
version: '1.0.0', version: '1.0.0',
}); });
transport = new StreamableHTTPClientTransport( transport = new StreamableHTTPClientTransport(
new URL(`http://localhost:${port}/mcp`), new URL(`http://${getIdeServerHost()}:${port}/mcp`),
); );
await this.client.connect(transport); await this.client.connect(transport);
this.registerClientHandlers(); this.registerClientHandlers();
@ -345,3 +345,12 @@ export class IdeClient {
} }
} }
} }
function getIdeServerHost() {
const isInContainer =
fs.existsSync('/.dockerenv') ||
fs.existsSync('/run/.containerenv') ||
!!process.env.SANDBOX ||
!!process.env.container;
return isInContainer ? 'host.docker.internal' : 'localhost';
}