Skip to content

Chat: apply network filter when agent sandbox is enabled#310355

Open
dileepyavan wants to merge 4 commits intomicrosoft:mainfrom
dileepyavan:DileepY/309954
Open

Chat: apply network filter when agent sandbox is enabled#310355
dileepyavan wants to merge 4 commits intomicrosoft:mainfrom
dileepyavan:DileepY/309954

Conversation

@dileepyavan
Copy link
Copy Markdown
Member

Summary

  • Apply agent network domain filtering to fetch and integrated browser tools when chat agent sandboxing is enabled
  • Add shared sandbox setting IDs under platform/sandbox/common
  • Update configuration descriptions for allowed/denied domains and add network filter unit coverage

Validation

  • git diff --cached --check before commit
  • Precommit hygiene ran successfully during git commit
  • Diagnostics: no errors in touched files

Fixes #309954

Copilot AI review requested due to automatic review settings April 16, 2026 00:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aligns agent tool safety behavior with chat agent sandboxing by (1) activating network domain filtering whenever sandboxing is enabled and (2) ensuring terminal command auto-approval isn’t implicitly forced when auto-approve is disabled. It also centralizes sandbox setting IDs and adds unit coverage for the updated behaviors.

Changes:

  • Activate AgentNetworkFilterService domain filtering when chat.agent.sandbox.enabled (or deprecated chat.agent.sandbox) is enabled, even if chat.agent.networkFilter is disabled.
  • Update CommandLineSandboxAnalyzer to respect chat.tools.terminal.enableAutoApprove when deciding whether to force auto-approval.
  • Introduce shared sandbox setting IDs in src/vs/platform/sandbox/common and expand unit tests for network filtering and terminal sandbox analyzer behavior.
Show a summary per file
File Description
src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/browser/commandLineSandboxAnalyzer.test.ts Adds unit tests for sandbox analyzer auto-approval behavior.
src/vs/workbench/contrib/terminalContrib/chatAgentTools/common/terminalChatAgentToolsConfiguration.ts Switches sandbox setting IDs to shared AgentSandboxSettingId constants.
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/commandLineAnalyzer/commandLineSandboxAnalyzer.ts Updates sandbox analyzer to consult EnableAutoApprove before forcing auto-approval.
src/vs/workbench/contrib/chat/browser/chat.contribution.ts Updates setting descriptions to reflect sandbox-triggered domain filtering behavior.
src/vs/platform/sandbox/common/settings.ts Adds shared AgentSandboxSettingId setting ID constants.
src/vs/platform/networkFilter/test/common/networkFilterService.test.ts Adds unit tests for sandbox-triggered filtering and configuration-change behavior.
src/vs/platform/networkFilter/common/networkFilterService.ts Enables network filtering when sandbox settings indicate sandboxing is enabled.

Copilot's findings

  • Files reviewed: 7/7 changed files
  • Comments generated: 4

}

private _isAutoApproveEnabled(): boolean {
return this._configurationService.getValue(TerminalChatAgentToolsSettingId.EnableAutoApprove) !== false;
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

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

_isAutoApproveEnabled uses an untyped getValue(...) !== false check, which will treat any non-false value (including invalid types like 'true'/null) as enabled and is inconsistent with other call sites that use getValue<boolean>(...) === true. Consider reading a boolean (getValue<boolean>(...)) and explicitly falling back to the setting default (currently true) to avoid accidentally enabling auto-approve on malformed configuration values.

Suggested change
return this._configurationService.getValue(TerminalChatAgentToolsSettingId.EnableAutoApprove) !== false;
const isAutoApproveEnabled = this._configurationService.getValue<boolean>(TerminalChatAgentToolsSettingId.EnableAutoApprove);
return isAutoApproveEnabled ?? true;

Copilot uses AI. Check for mistakes.
Comment on lines 24 to +25
async analyze(_options: ICommandLineAnalyzerOptions): Promise<ICommandLineAnalyzerResult> {
const isAutoApproveEnabled = this._isAutoApproveEnabled();
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

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

analyze takes _options but the parameter is actually used. Dropping the leading underscore would better match the convention of using _ only for intentionally-unused parameters.

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +42 to +49
function setConfig(key: string, value: unknown) {
configurationService.setUserConfiguration(key, value);
configurationService.onDidChangeConfigurationEmitter.fire({
affectsConfiguration: () => true,
affectedKeys: new Set([key]),
source: ConfigurationTarget.USER,
change: null!,
});
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

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

The helper setConfig manually fires onDidChangeConfigurationEmitter with affectsConfiguration: () => true and change: null!. Because workbenchInstantiationService wires up many services that may listen to configuration changes, this broad event (and null change) can make the test brittle or cause unrelated listeners to throw. Consider either not firing an event at all (the analyzer reads the config on-demand), or firing a well-formed change event scoped to the specific key (like other tests in the repo) with a non-null change payload and affectsConfiguration only returning true for that key.

Copilot uses AI. Check for mistakes.
Comment on lines +85 to +89
const networkFilterEnabled = this.configurationService.getValue<boolean>(AgentNetworkDomainSettingId.NetworkFilter) ?? false;
const sandboxEnabled = this.configurationService.getValue<'off' | 'on'>(AgentSandboxSettingId.Enabled) === 'on';
const deprecatedSandboxEnabled = this.configurationService.getValue<boolean>(AgentSandboxSettingId.DeprecatedEnabled) ?? false;

this.enabled = networkFilterEnabled || sandboxEnabled || deprecatedSandboxEnabled;
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

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

chat.agent.sandbox.enabled is treated as enabled only when the value is the string 'on'. Elsewhere (e.g. TerminalSandboxService) the setting is interpreted as enabled for both 'on' and boolean true, so a user configuration like "chat.agent.sandbox.enabled": true would enable the sandbox but not activate network domain filtering here. Consider normalizing the setting value (accept 'on' and true as enabled) so network filtering reliably follows sandbox enablement, and add a unit test for the boolean case.

See below for a potential fix:

	private isSandboxEnabled(value: 'off' | 'on' | boolean | undefined): boolean {
		return value === 'on' || value === true;
	}

	private readConfiguration(): void {
		const networkFilterEnabled = this.configurationService.getValue<boolean>(AgentNetworkDomainSettingId.NetworkFilter) ?? false;
		const sandboxEnabled = this.isSandboxEnabled(this.configurationService.getValue<'off' | 'on' | boolean>(AgentSandboxSettingId.Enabled));

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enabling sandbox auto-allows commands even when chat.tools.terminal.enableAutoApprove is disabled

3 participants