summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchristine betts <[email protected]>2025-08-08 15:35:47 +0000
committerGitHub <[email protected]>2025-08-08 15:35:47 +0000
commit5ec4ea9b4d425269c9e9052503ad85b5caaa976e (patch)
tree41a881d5bcb4bf214bf1bc8b4adb86b4f852ee71
parent407393b1285ed648be6594395429a802e876b20c (diff)
[ide-mode] Wire up env variables to sandbox (#5804)
-rw-r--r--packages/cli/src/utils/sandbox.ts11
-rw-r--r--packages/core/src/ide/ide-client.ts11
2 files changed, 21 insertions, 1 deletions
diff --git a/packages/cli/src/utils/sandbox.ts b/packages/cli/src/utils/sandbox.ts
index 3550f45b..dfd2065f 100644
--- a/packages/cli/src/utils/sandbox.ts
+++ b/packages/cli/src/utils/sandbox.ts
@@ -614,6 +614,17 @@ export async function start_sandbox(
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
// 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)
diff --git a/packages/core/src/ide/ide-client.ts b/packages/core/src/ide/ide-client.ts
index 508dfea1..5ffcc2e3 100644
--- a/packages/core/src/ide/ide-client.ts
+++ b/packages/core/src/ide/ide-client.ts
@@ -324,7 +324,7 @@ export class IdeClient {
version: '1.0.0',
});
transport = new StreamableHTTPClientTransport(
- new URL(`http://localhost:${port}/mcp`),
+ new URL(`http://${getIdeServerHost()}:${port}/mcp`),
);
await this.client.connect(transport);
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';
+}