openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
162 lines (161 loc) • 7.47 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { R as resolveTimerTimeoutMs } from "./number-coercion-D6u-4YD8.mjs";
import { p as normalizeSecretInputString } from "./types.secrets-BmNLLnHp.mjs";
import { r as resolveAgentConfig } from "./agent-scope-config-DmXgFGKP.mjs";
import { n as resolveSandboxScope, t as resolveSandboxDockerEnv } from "./config-contract-D5fpm2xx.mjs";
import { t as DEFAULT_SANDBOX_BROWSER_NETWORK } from "./browser-network-BG6jdrVm.mjs";
import { a as DEFAULT_SANDBOX_BROWSER_PREFIX, c as DEFAULT_SANDBOX_CONTAINER_PREFIX, d as DEFAULT_SANDBOX_MAX_AGE_DAYS, f as DEFAULT_SANDBOX_WORKDIR, i as DEFAULT_SANDBOX_BROWSER_NOVNC_PORT, l as DEFAULT_SANDBOX_IDLE_HOURS, n as DEFAULT_SANDBOX_BROWSER_CDP_PORT, o as DEFAULT_SANDBOX_BROWSER_VNC_PORT, p as DEFAULT_SANDBOX_WORKSPACE_ROOT, r as DEFAULT_SANDBOX_BROWSER_IMAGE, t as DEFAULT_SANDBOX_BROWSER_AUTOSTART_TIMEOUT_MS, u as DEFAULT_SANDBOX_IMAGE } from "./constants-Dxjr8D5t.mjs";
import { i as SANDBOX_DEFAULT_TOOL_ALLOW, r as resolveSandboxToolPolicyForAgent } from "./tool-policy-DsT-JaIj.mjs";
//#region src/agents/sandbox/config.ts
const DANGEROUS_SANDBOX_DOCKER_BOOLEAN_KEYS = [
"dangerouslyAllowReservedContainerTargets",
"dangerouslyAllowExternalBindSources",
"dangerouslyAllowContainerNamespaceJoin"
];
const DEFAULT_SANDBOX_SSH_COMMAND = "ssh";
const DEFAULT_SANDBOX_SSH_WORKSPACE_ROOT = "/tmp/openclaw-sandboxes";
function resolveDangerousSandboxDockerBooleans(e, t) {
const n = {};
for (const r of DANGEROUS_SANDBOX_DOCKER_BOOLEAN_KEYS) n[r] = e?.[r] ?? t?.[r];
return n;
}
function resolveSandboxBrowserDockerCreateConfig(e) {
const t = e.browser.network.trim();
const n = {
...e.docker,
network: t || "openclaw-sandbox-browser",
image: e.browser.image
};
return e.browser.binds !== void 0 ? {
...n,
binds: e.browser.binds
} : n;
}
function resolveSandboxDockerConfig(e, t, n) {
const r = resolveSandboxDockerEnv({
scope: e,
globalEnv: t?.env,
agentEnv: n?.env
});
const i = n?.ulimits ? {
...t?.ulimits,
...n.ulimits
} : t?.ulimits;
const a = [...t?.binds ?? [], ...n?.binds ?? []];
return {
image: n?.image ?? t?.image ?? "openclaw-sandbox:trixie-slim",
containerPrefix: n?.containerPrefix ?? t?.containerPrefix ?? "openclaw-sbx-",
workdir: n?.workdir ?? t?.workdir ?? "/workspace",
readOnlyRoot: n?.readOnlyRoot ?? t?.readOnlyRoot ?? true,
tmpfs: n?.tmpfs ?? t?.tmpfs ?? [
"/tmp",
"/var/tmp",
"/run"
],
network: n?.network ?? t?.network ?? "none",
user: n?.user ?? t?.user,
capDrop: n?.capDrop ?? t?.capDrop ?? ["ALL"],
env: r,
setupCommand: n?.setupCommand ?? t?.setupCommand,
pidsLimit: n?.pidsLimit ?? t?.pidsLimit ?? 1024,
memory: n?.memory ?? t?.memory,
memorySwap: n?.memorySwap ?? t?.memorySwap,
cpus: n?.cpus ?? t?.cpus,
gpus: normalizeOptionalString(n?.gpus ?? t?.gpus),
ulimits: i,
seccompProfile: n?.seccompProfile ?? t?.seccompProfile,
apparmorProfile: n?.apparmorProfile ?? t?.apparmorProfile,
dns: n?.dns ?? t?.dns,
extraHosts: n?.extraHosts ?? t?.extraHosts,
binds: a.length ? a : void 0,
...resolveDangerousSandboxDockerBooleans(n, t)
};
}
function resolveSandboxBrowserConfig(e, t) {
const n = [...e?.binds ?? [], ...t?.binds ?? []];
const r = e?.binds !== void 0 || t?.binds !== void 0;
return {
enabled: t?.enabled ?? e?.enabled ?? false,
image: t?.image ?? e?.image ?? "openclaw-sandbox-browser:trixie-slim",
containerPrefix: t?.containerPrefix ?? e?.containerPrefix ?? "openclaw-sbx-browser-",
network: t?.network ?? e?.network ?? "openclaw-sandbox-browser",
cdpPort: t?.cdpPort ?? e?.cdpPort ?? 9222,
cdpSourceRange: t?.cdpSourceRange ?? e?.cdpSourceRange,
vncPort: t?.vncPort ?? e?.vncPort ?? 5900,
noVncPort: t?.noVncPort ?? e?.noVncPort ?? 6080,
headless: t?.headless ?? e?.headless ?? false,
noVncEnabled: t?.noVncEnabled ?? e?.noVncEnabled ?? true,
allowHostControl: t?.allowHostControl ?? e?.allowHostControl ?? false,
autoStart: t?.autoStart ?? e?.autoStart ?? true,
autoStartTimeoutMs: resolveTimerTimeoutMs(t?.autoStartTimeoutMs ?? e?.autoStartTimeoutMs, DEFAULT_SANDBOX_BROWSER_AUTOSTART_TIMEOUT_MS),
binds: r ? n : void 0
};
}
function resolveSandboxPruneConfig(e, t) {
return {
idleHours: t?.idleHours ?? e?.idleHours ?? 24,
maxAgeDays: t?.maxAgeDays ?? e?.maxAgeDays ?? 7
};
}
function normalizeRemoteRoot(e, t) {
const n = normalizeOptionalString(e) ?? t;
const r = n.replaceAll("\\", "/");
if (!r.startsWith("/")) throw new Error(`Sandbox SSH workspaceRoot must be an absolute POSIX path: ${n}`);
return r.replace(/\/+$/g, "") || "/";
}
function resolveSandboxSshConfig(e, t, n) {
return {
target: normalizeOptionalString(n?.target ?? t?.target),
command: normalizeOptionalString(n?.command ?? t?.command) ?? DEFAULT_SANDBOX_SSH_COMMAND,
workspaceRoot: e,
strictHostKeyChecking: n?.strictHostKeyChecking ?? t?.strictHostKeyChecking ?? true,
updateHostKeys: n?.updateHostKeys ?? t?.updateHostKeys ?? true,
identityFile: normalizeOptionalString(n?.identityFile ?? t?.identityFile),
certificateFile: normalizeOptionalString(n?.certificateFile ?? t?.certificateFile),
knownHostsFile: normalizeOptionalString(n?.knownHostsFile ?? t?.knownHostsFile),
identityData: normalizeSecretInputString(n?.identityData ?? t?.identityData),
certificateData: normalizeSecretInputString(n?.certificateData ?? t?.certificateData),
knownHostsData: normalizeSecretInputString(n?.knownHostsData ?? t?.knownHostsData)
};
}
/** Snapshot resolved policy without losing its in-process default-allow provenance. */
function captureSandboxConfig(e) {
const t = structuredClone(e);
const n = e.tools[SANDBOX_DEFAULT_TOOL_ALLOW];
if (n) t.tools[SANDBOX_DEFAULT_TOOL_ALLOW] = n === e.tools.allow ? t.tools.allow : [...n];
return t;
}
/** Classification needs policy facts, not materialized container settings. */
function resolveSandboxRuntimeSettings(e, t) {
const n = resolveSandboxScope({ scope: t?.scope ?? e?.scope });
const r = n === "shared" ? void 0 : t;
return {
scope: n,
mode: t?.mode ?? e?.mode ?? "off",
workspaceAccess: t?.workspaceAccess ?? e?.workspaceAccess ?? "none",
sshWorkspaceRoot: normalizeRemoteRoot(r?.ssh?.workspaceRoot ?? e?.ssh?.workspaceRoot, DEFAULT_SANDBOX_SSH_WORKSPACE_ROOT)
};
}
function resolveSandboxConfigForAgent(e, t) {
const n = e?.agents?.defaults?.sandbox;
const r = (e && t ? resolveAgentConfig(e, t) : void 0)?.sandbox;
const i = resolveSandboxRuntimeSettings(n, r);
const a = i.scope;
const { sources: o, ...s } = resolveSandboxToolPolicyForAgent(e, t);
const c = a === "shared" ? void 0 : r;
return {
mode: i.mode,
backend: r?.backend?.trim() || n?.backend?.trim() || "docker",
scope: a,
workspaceAccess: i.workspaceAccess,
workspaceRoot: r?.workspaceRoot ?? n?.workspaceRoot ?? DEFAULT_SANDBOX_WORKSPACE_ROOT,
dockerTmpfsSource: c?.docker?.tmpfs === void 0 && n?.docker?.tmpfs === void 0 ? "default" : "configured",
docker: resolveSandboxDockerConfig(a, n?.docker, c?.docker),
ssh: resolveSandboxSshConfig(i.sshWorkspaceRoot, n?.ssh, c?.ssh),
browser: resolveSandboxBrowserConfig(n?.browser, c?.browser),
tools: s,
prune: resolveSandboxPruneConfig(n?.prune, c?.prune)
};
}
//#endregion
export { resolveSandboxRuntimeSettings as a, resolveSandboxConfigForAgent as i, captureSandboxConfig as n, resolveSandboxBrowserDockerCreateConfig as r, DANGEROUS_SANDBOX_DOCKER_BOOLEAN_KEYS as t };