eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 1.41 kB
JavaScript
import{WORKSPACE_ROOT}from"#runtime/workspace/types.js";import{buildDockerBaseSetupScript}from"#execution/sandbox/bindings/docker-base-setup.js";import{expectDockerSuccess}from"#execution/sandbox/bindings/docker-utils.js";import{withDevelopmentSandboxTags}from"#execution/sandbox/development-run.js";const DOCKER_SANDBOX_LABEL=`eve.sandbox`,DOCKER_KEEPALIVE_ARGS=[`-c`,`sleep 2147483647`];async function startDockerContainer(t){let i=[`run`,`-d`,`--name`,t.containerName,`--label`,`${DOCKER_SANDBOX_LABEL}=1`,`--label`,`${DOCKER_SANDBOX_LABEL}.role=${t.role}`];for(let[e,n]of Object.entries(withDevelopmentSandboxTags(t.tags)??{}))i.push(`--label`,`${DOCKER_SANDBOX_LABEL}.tag.${e}=${n}`);for(let[e,n]of Object.entries(t.options.env))i.push(`-e`,`${e}=${n}`);t.initialNetworkPolicy===`deny-all`&&i.push(`--network`,`none`),i.push(`--workdir`,WORKSPACE_ROOT,`--entrypoint`,`/bin/sh`,t.image,...DOCKER_KEEPALIVE_ARGS),expectDockerSuccess(await t.cli.run(i),`start sandbox container "${t.containerName}" from "${t.image}"`)}async function runDockerBaseSetup(e,r){expectDockerSuccess(await e.run([`exec`,`--user`,`root`,r,`/bin/sh`,`-c`,buildDockerBaseSetupScript()]),`prepare base runtime in sandbox container "${r}"`)}async function stopDockerContainerIfRunning(e,t){await e.run([`stop`,`-t`,`0`,t]).catch(()=>{})}export{DOCKER_SANDBOX_LABEL,runDockerBaseSetup,startDockerContainer,stopDockerContainerIfRunning};