fix(sandbox): cap browser autostart timeout

This commit is contained in:
Peter Steinberger
2026-05-30 04:26:41 -04:00
parent 26ef325219
commit d8db7f561e
2 changed files with 32 additions and 4 deletions

View File

@@ -0,0 +1,24 @@
import { describe, expect, it } from "vitest";
import type { OpenClawConfig } from "../../config/config.js";
import { MAX_TIMER_TIMEOUT_MS } from "../../shared/number-coercion.js";
import { resolveSandboxConfigForAgent } from "./config.js";
describe("sandbox config", () => {
it("caps browser autostart timeout to a timer-safe delay", () => {
const cfg: OpenClawConfig = {
agents: {
defaults: {
sandbox: {
browser: {
autoStartTimeoutMs: Number.MAX_SAFE_INTEGER,
},
},
},
},
};
expect(resolveSandboxConfigForAgent(cfg, "main").browser.autoStartTimeoutMs).toBe(
MAX_TIMER_TIMEOUT_MS,
);
});
});

View File

@@ -1,6 +1,7 @@
import type { OpenClawConfig } from "../../config/types.openclaw.js";
import type { SandboxSshSettings } from "../../config/types.sandbox.js";
import { normalizeSecretInputString } from "../../config/types.secrets.js";
import { resolveTimerTimeoutMs } from "../../shared/number-coercion.js";
import { normalizeOptionalString } from "../../shared/string-coerce.js";
import { resolveAgentConfig } from "../agent-scope.js";
import {
@@ -40,6 +41,10 @@ const DEFAULT_SANDBOX_SSH_WORKSPACE_ROOT = "/tmp/openclaw-sandboxes";
type DangerousSandboxDockerBooleanKey = (typeof DANGEROUS_SANDBOX_DOCKER_BOOLEAN_KEYS)[number];
type DangerousSandboxDockerBooleans = Pick<SandboxDockerConfig, DangerousSandboxDockerBooleanKey>;
function resolveSandboxBrowserAutoStartTimeoutMs(value: number | undefined): number {
return resolveTimerTimeoutMs(value, DEFAULT_SANDBOX_BROWSER_AUTOSTART_TIMEOUT_MS);
}
function resolveDangerousSandboxDockerBooleans(
agentDocker?: Partial<SandboxDockerConfig>,
globalDocker?: Partial<SandboxDockerConfig>,
@@ -154,10 +159,9 @@ export function resolveSandboxBrowserConfig(params: {
enableNoVnc: agentBrowser?.enableNoVnc ?? globalBrowser?.enableNoVnc ?? true,
allowHostControl: agentBrowser?.allowHostControl ?? globalBrowser?.allowHostControl ?? false,
autoStart: agentBrowser?.autoStart ?? globalBrowser?.autoStart ?? true,
autoStartTimeoutMs:
agentBrowser?.autoStartTimeoutMs ??
globalBrowser?.autoStartTimeoutMs ??
DEFAULT_SANDBOX_BROWSER_AUTOSTART_TIMEOUT_MS,
autoStartTimeoutMs: resolveSandboxBrowserAutoStartTimeoutMs(
agentBrowser?.autoStartTimeoutMs ?? globalBrowser?.autoStartTimeoutMs,
),
binds: bindsConfigured ? binds : undefined,
};
}