1
>
/*---------------------------------------------------------------------------------------------
sandboxSettingsReader.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js';
7
>
import { ILogService } from '../../../../../platform/log/common/log.js';
8
>
import { AgentNetworkDomainSettingId } from '../../../../../platform/networkFilter/common/settings.js';
9
>
import { AgentSandboxSettingId } from '../../../../../platform/sandbox/common/settings.js';
10
>
import { sandboxSettingIdToAgentHostKey } from '../../../../../platform/agentHost/common/sandboxConfigSchema.js';
11
>
12
>
/** Setting IDs that affect the engine's sandbox configuration (modern + deprecated). */
13
>
export const SANDBOX_SETTING_KEYS: readonly string[] = [
14
>
AgentSandboxSettingId.AgentSandboxEnabled,
15
>
AgentSandboxSettingId.AgentSandboxWindowsEnabled,
16
>
AgentSandboxSettingId.AgentSandboxAllowNetwork,
17
>
AgentSandboxSettingId.AgentSandboxAllowUnsandboxedCommands,
18
>
AgentSandboxSettingId.AgentSandboxLinuxFileSystem,
19
>
AgentSandboxSettingId.AgentSandboxMacFileSystem,
20
>
AgentSandboxSettingId.AgentSandboxWindowsFileSystem,
21
>
AgentSandboxSettingId.AgentSandboxWindowsSchemaVersion,
22
>
AgentSandboxSettingId.AgentSandboxAdvancedRuntime,
23
>
AgentSandboxSettingId.DeprecatedAgentSandboxEnabled,
24
>
AgentSandboxSettingId.DeprecatedAgentSandboxLinuxFileSystem,
25
>
AgentSandboxSettingId.DeprecatedAgentSandboxMacFileSystem,
26
>
AgentNetworkDomainSettingId.AllowedNetworkDomains,
27
>
AgentNetworkDomainSettingId.DeniedNetworkDomains,
28
>
AgentNetworkDomainSettingId.DeprecatedSandboxAllowedNetworkDomains,
29
>
AgentNetworkDomainSettingId.DeprecatedSandboxDeniedNetworkDomains,
30
>
AgentNetworkDomainSettingId.DeprecatedOldAllowedNetworkDomains,
31
>
AgentNetworkDomainSettingId.DeprecatedOldDeniedNetworkDomains,
32
>
];
33
>
34
>
/**
35
>
* Maps each modern sandbox setting ID to the ordered list of deprecated
36
>
* setting IDs the workbench should fall back to when the modern key has not
37
>
* been configured by the user. Consumers (engine adapter, agent-host
38
>
* forwarder) only ever resolve values by modern key.
39
>
*/
40
>
const DEPRECATED_SANDBOX_FALLBACKS: Readonly<Record<string, readonly string[]>> = {
41
>
[AgentSandboxSettingId.AgentSandboxEnabled]: [AgentSandboxSettingId.DeprecatedAgentSandboxEnabled],
42
>
[AgentSandboxSettingId.AgentSandboxLinuxFileSystem]: [AgentSandboxSettingId.DeprecatedAgentSandboxLinuxFileSystem],
43
>
[AgentSandboxSettingId.AgentSandboxMacFileSystem]: [AgentSandboxSettingId.DeprecatedAgentSandboxMacFileSystem],
44
>
[AgentNetworkDomainSettingId.AllowedNetworkDomains]: [AgentNetworkDomainSettingId.DeprecatedSandboxAllowedNetworkDomains, AgentNetworkDomainSettingId.DeprecatedOldAllowedNetworkDomains],
45
>
[AgentNetworkDomainSettingId.DeniedNetworkDomains]: [AgentNetworkDomainSettingId.DeprecatedSandboxDeniedNetworkDomains, AgentNetworkDomainSettingId.DeprecatedOldDeniedNetworkDomains],
46
>
};
47
>
48
>
/**
49
>
* Reads a single sandbox-related setting from `IConfigurationService`,
50
>
* preferring the modern key and falling back to its deprecated peers in
51
>
* order. Legacy boolean sandbox enabled values are normalized to the agent-host
52
>
* `'on' | 'off'` enum. Returns `undefined` when no user value is configured.
53
>
*/
54
>
export function readSandboxSetting<T>(configurationService: IConfigurationService, logService: ILogService, settingId: string): T | undefined {
55
>
const modern = configurationService.inspect<T>(settingId);
56
>
if (modern.userValue !== undefined) {
57
return normalizeSandboxSettingValue<T>(settingId, modern.value);
58
}
59
const deprecatedFallbacks = DEPRECATED_SANDBOX_FALLBACKS[settingId];
61
// Some deprecated keys are namespace parents of newer settings (e.g.
62
// `chat.agent.sandbox` vs `chat.agent.sandbox.fileSystem.linux`).