Skip to content

feat(browser): add sandbox-aware browser agent initialization#24419

Merged
gsquared94 merged 4 commits intogoogle-gemini:mainfrom
gsquared94:feat/browser-agent-sandbox-mode
Apr 1, 2026
Merged

feat(browser): add sandbox-aware browser agent initialization#24419
gsquared94 merged 4 commits intogoogle-gemini:mainfrom
gsquared94:feat/browser-agent-sandbox-mode

Conversation

@gsquared94
Copy link
Copy Markdown
Contributor

Summary

Add environment-aware initialization for the browser agent to support macOS Seatbelt and container-based (Docker/Podman) sandboxes. Previously, the browser agent would fail with permission errors or DevToolsActivePort crashes when running inside sandboxed environments.

Changes

Registration Gating (registry.ts)

  • Skip browser agent registration in container sandboxes unless sessionMode is set to "existing"
  • Emit user-visible feedback with remediation steps when the agent is disabled

Sandbox-Aware Configuration (browserManager.ts)

  • macOS Seatbelt (sandbox-exec): Force isolated + headless modes for filesystem compatibility (persistent profiles conflict with seatbelt restrictions)
  • Container sandboxes (Docker/Podman): When sessionMode: "existing", auto-configure --browser-url with the resolved IP of host.docker.internal instead of --autoConnect (which fails in containers due to local pipe/socket restrictions)
  • Resolve host.docker.internal to IP via dns.promises.lookup() because Chrome's DevTools protocol rejects HTTP requests where the Host header is not localhost or an IP address

Tests

  • 4 browserManager tests: seatbelt override, seatbelt+existing passthrough, container+DNS resolution, no-sandbox baseline
  • 4 registry tests: container gating, existing bypass, seatbelt passthrough, no-sandbox baseline

Environment Detection

  • SANDBOX=sandbox-exec → macOS Seatbelt
  • SANDBOX=<container-name> → Docker/Podman/gVisor/LXC container

Testing

  • All 54 browserManager tests pass ✅
  • All registry tests pass ✅
  • Docker E2E: browser agent successfully navigated to nytimes.com from inside a Docker container via Chrome on the host ✅

@gsquared94 gsquared94 requested a review from a team as a code owner April 1, 2026 11:58
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 environment-aware initialization for the browser agent to ensure compatibility when running within sandboxed environments like macOS Seatbelt or containers (Docker/Podman). The changes ensure that the agent gracefully handles restricted filesystem access and network limitations by adjusting configuration parameters and providing clear feedback to the user when specific modes are required.

Highlights

  • Environment-Aware Initialization: Implemented detection for macOS Seatbelt and container-based sandboxes to adjust browser agent behavior dynamically.
  • Sandbox-Specific Configuration: Forced 'isolated' and 'headless' modes in macOS Seatbelt environments and enabled remote connection via host IP resolution for containerized environments.
  • Registration Gating: Added logic to disable the browser agent in container sandboxes unless 'existing' session mode is configured, providing user-friendly remediation feedback.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces sandbox-aware logic for the browser agent to improve compatibility with Seatbelt (macOS) and containerized environments like Docker. In Seatbelt sandboxes, the agent now forces isolated and headless modes, while in container sandboxes, it requires an "existing" session mode and resolves the host IP to connect to Chrome's DevTools protocol. Feedback was provided regarding the hardcoded port 9222, suggesting it should be made configurable within the browser agent settings.

`Could not resolve host.docker.internal, using hostname directly`,
);
}
const browserUrl = `http://${browserHost}:9222`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The remote debugging port 9222 is hardcoded. While this is a common default, it should be configurable to support environments where a different port is used for security or to avoid conflicts. This is especially relevant for the container-based connection this PR is adding.

I recommend adding a remoteDebuggingPort property to BrowserAgentCustomConfig in packages/core/src/config/config.ts and using it here.

Example implementation:

// In packages/core/src/config/config.ts
export interface BrowserAgentCustomConfig {
  // ... existing properties
  remoteDebuggingPort?: number;
}
// In this file (packages/core/src/agents/browser/browserManager.ts)
const remoteDebuggingPort = this.config.getBrowserAgentConfig().customConfig.remoteDebuggingPort ?? 9222;
const browserUrl = `http://${browserHost}:${remoteDebuggingPort}`;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will keep as-is unless it's brought up as a pain-point later on.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe mention in readme that it is a hard coded port number that user cannot customize it for now

@gsquared94 gsquared94 requested a review from a team as a code owner April 1, 2026 12:18
@gemini-cli gemini-cli bot added the status/need-issue Pull requests that need to have an associated issue. label Apr 1, 2026
Copy link
Copy Markdown
Contributor

@cynthialong0-0 cynthialong0-0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM pending on a few nits.

`Could not resolve host.docker.internal, using hostname directly`,
);
}
const browserUrl = `http://${browserHost}:9222`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe mention in readme that it is a hard coded port number that user cannot customize it for now

@gsquared94 gsquared94 enabled auto-merge April 1, 2026 14:36
- Gate browser agent registration in container sandboxes unless
  sessionMode is set to 'existing' (registry.ts)
- Force isolated+headless mode in macOS seatbelt sandboxes for
  filesystem compatibility (browserManager.ts)
- Auto-configure --browser-url with DNS-resolved host IP for
  container sandboxes, working around Chrome's DevTools Host
  header restriction (browserManager.ts)
- Add 8 integration tests covering all sandbox overrides and
  registration gating
The CI workflow sets SANDBOX='sandbox:none' as metadata on macOS and
Windows runners. The isContainerSandbox check treated this as a real
container sandbox, causing browser-policy E2E tests to fail.
@gsquared94 gsquared94 force-pushed the feat/browser-agent-sandbox-mode branch from 9a0cae5 to 759853b Compare April 1, 2026 16:42
@gsquared94 gsquared94 added this pull request to the merge queue Apr 1, 2026
Merged via the queue into google-gemini:main with commit bf3ac20 Apr 1, 2026
27 of 28 checks passed
@gsquared94 gsquared94 deleted the feat/browser-agent-sandbox-mode branch April 1, 2026 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants