UNPKG

eve

Version:

Filesystem-first framework for durable backend AI agents that run anywhere.

1 lines 2.69 kB
import{resolveSelfModificationConfig}from"./config.js";import{createGitHubCredentialProvider}from"./credentials.js";import{SELF_MODIFICATION_BASELINE_NETWORK_POLICY}from"./network-policy.js";import{resolveSelfModificationMode}from"./mode.js";import{REPOSITORY_PATH,prepareSelfModificationWorkspace}from"./git-workspace.js";import{createSelfModificationFilesystem}from"./filesystem.js";import{bindSandboxEnvironment}from"#shared/sandbox-environment.js";import{shellQuote}from"#shared/shell-quote.js";import{defineSandbox}from"#public/definitions/sandbox.js";import{SANDBOX_PROVIDER_PROBES}from"#sandbox/providers/default.js";import{JustBashSandbox}from"#sandbox/providers/just-bash.js";import{MicrosandboxSandbox}from"#sandbox/providers/microsandbox.js";import{VercelSandbox}from"#sandbox/providers/vercel.js";function defineSelfModificationSandbox(e={}){let t=resolveSelfModificationConfig(e.config),n=resolveSelfModificationMode(t);if(n!==`deployed`){let e=n===`local`?JustBashSandbox.environment({filesystem:createSelfModificationFilesystem}):JustBashSandbox.environment();return bindSandboxEnvironment(defineSandbox(()=>e.open()),e)}let r=selectDeployedSelfModificationEnvironment(SANDBOX_PROVIDER_PROBES);return bindSandboxEnvironment(defineSandbox(async({session:e})=>{let n=await r.open({networkPolicy:SELF_MODIFICATION_BASELINE_NETWORK_POLICY});if(t.deployed===void 0)return n;if(e.parent===void 0)throw Error(`Production self-modification requires a child session.`);if(n.setNetworkPolicy===void 0)throw Error(`Production self-modification requires mutable sandbox network policy.`);let i={...n,setNetworkPolicy:n.setNetworkPolicy},a=t.deployed,o=await createGitHubCredentialProvider(a.credentials).resolve({capability:`checkout`,repository:a.repository});await prepareSelfModificationWorkspace({directory:a.directory,repository:a.repository,sandbox:i,targetBranch:a.targetBranch,token:o});let s=a.directory===`.`?REPOSITORY_PATH:`${REPOSITORY_PATH}/${a.directory}`;if((await n.run({command:`rm -rf /source && ln -s ${shellQuote(`${s}/agent`)} /source`})).exitCode!==0)throw Error(`Self-modification could not mount the agent source.`);return n}),r)}function selectDeployedSelfModificationEnvironment(e){if(e.isDeployedOnVercel())return VercelSandbox.environment();if(e.isMicrosandboxSupported())return MicrosandboxSandbox.environment();throw Error(`Deployed self-modification requires runtime credential transforms. No supported provider is available. Use Vercel Sandbox or microsandbox on a supported self-hosted system.`)}var sandbox_default=defineSelfModificationSandbox();export{sandbox_default as default,defineSelfModificationSandbox,selectDeployedSelfModificationEnvironment};