UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

6 lines • 4.59 kB
import{p as toErrorObject}from"./error-coercion-DlKnt6w-.mjs";import{i as createAbortError}from"./src-De06gkOi.mjs";import"./abort-signal-BKkRe6pu.mjs";import"./errors-D37BJTfI.mjs";import{s as isPlainCommandExitFailure}from"./exec-result-TD4w1Z1i.mjs";import{a as resolveGatewayServiceCgroupDirectory}from"./linux-exec-cgroup-kO5YhBoe.mjs";import{l as spawnCommand}from"./exec-spawn-DNCbDcyJ.mjs";import"./exec-c5tqm8tb.mjs";import{x as SANDBOX_COMMAND_MAX_BUFFER_BYTES}from"./constants-8_hxvRih.mjs";import{t as stripGatewayAllocatorEnv}from"./child-env-BMJCgISK.mjs"; //!src/agents/sandbox/container-keyring.ts function isSandboxKeyringQuotaError(e){return e instanceof Error&&/create keyring/iu.test(e.message)&&/disk quota exceeded|\bEDQUOT\b/iu.test(e.message)}function sandboxKeyringQuotaError(e){return new Error(`Sandbox cannot start: the container engine host's per-user kernel keyring quota is exhausted. Ask the host operator to raise sysctl kernel.keys.maxkeys and kernel.keys.maxbytes above their current values, persist both in /etc/sysctl.d, or reduce running sandboxes, then retry.`,{cause:e})} //!src/agents/sandbox/container-engine.ts const DOCKER_SANDBOX_ENGINE={id:`docker`,command:`docker`,displayName:`Docker`};const PODMAN_SANDBOX_ENGINE={id:`podman`,command:`podman`,displayName:`Podman`};function buildSandboxContainerEngineArgv(e,t){const n=[e.command,...e.globalArgs??[],...t];if(e.id!==`podman`||e.globalArgs?.[0]!==`--remote=false`||process.platform!==`linux`||process.getuid?.()===0)return n;try{if(!resolveGatewayServiceCgroupDirectory())return n}catch{return n}return[`systemd-run`,`--user`,`--scope`,`--quiet`,`--collect`,`--expand-environment=no`,`--description=OpenClaw-sandbox-runtime`,`--`,...n]}function missingContainerEngineMessage(e){if(e.id===`docker`)return'Sandbox mode requires Docker, but the "docker" command was not found in PATH. Install Docker (and check that "docker" is available), or set `agents.defaults.sandbox.mode=off` to disable sandboxing.';return'Sandbox mode requires Podman, but the "podman" command was not found in PATH. Install Podman (and check that "podman" is available), choose another sandbox backend, or set `agents.defaults.sandbox.mode=off` to disable sandboxing.'}async function execContainerRaw(e,t,n){let r;try{const i={...e.baseEnv??process.env};stripGatewayAllocatorEnv(i);if(n?.assertCurrent)await(n.prepareCurrent??e.stateGuard?.prepareHost)?.();n?.assertCurrent?.();r=await spawnCommand(buildSandboxContainerEngineArgv(e,t),{baseEnv:i,cancelSignal:n?.signal,encoding:`buffer`,input:n?.input??Buffer.alloc(0),maxBuffer:SANDBOX_COMMAND_MAX_BUFFER_BYTES,reject:false,stripFinalNewline:false})}catch(t){if(n?.signal?.aborted)throw createAbortError(`Aborted`);if(t.code===`ENOENT`)throw Object.assign(new Error(missingContainerEngineMessage(e)),{code:`INVALID_CONFIG`,cause:t});throw t}if(n?.signal?.aborted||r.isCanceled)throw createAbortError(`Aborted`);if(r.failed&&!isPlainCommandExitFailure(r)){if(r.code===`ENOENT`)throw Object.assign(new Error(missingContainerEngineMessage(e)),{code:`INVALID_CONFIG`,cause:r});throw toErrorObject(r,`${e.displayName} command execution failed`)}const i=Buffer.from(r.stdout);const a=Buffer.from(r.stderr);const o=r.exitCode??(r.failed?1:0);if(o!==0&&!n?.allowFailure){let n=a.length>0?a.toString(`utf8`).trim():``;if(e.id===`podman`&&t[0]===`create`&&/^(?:Error: )?(?:lookup init binary|container-init binary not found on the host):/mu.test(n))n+=` Install catatonit on the Podman engine host, or repair its configured init_path/helper_binaries_dir in containers.conf, then retry. The init executable must be available to the engine, not only inside the sandbox image. Keep --init and sandboxing enabled so orphaned processes are reaped.`;throw Object.assign(new Error(n||`${e.displayName} command failed (exit ${o})`),{code:o,stdout:i,stderr:a})}return{stdout:i,stderr:a,code:o}}async function execContainer(e,t,n){let r;try{r=await execContainerRaw(e,t,n)}catch(i){if(![`create`,`start`].includes(t[0]??``)||!isSandboxKeyringQuotaError(i))throw i;const{reclaimIdleSandboxContainer:a}=await import(`./container-keyring-recovery-DHJdI1Fs.mjs`);try{await a({engine:e,assertCurrent:n?.assertCurrent})}catch{}n?.assertCurrent?.();try{r=await execContainerRaw(e,t,n)}catch(e){if(!isSandboxKeyringQuotaError(e))throw e;throw sandboxKeyringQuotaError(e)}}return{stdout:r.stdout.toString(`utf8`),stderr:r.stderr.toString(`utf8`),code:r.code}}export{execContainerRaw as a,execContainer as i,PODMAN_SANDBOX_ENGINE as n,buildSandboxContainerEngineArgv as r,DOCKER_SANDBOX_ENGINE as t};