UNPKG

eve

Version:

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

1 lines • 1.22 kB
import{expectDockerSuccess}from"#execution/sandbox/bindings/docker-utils.js";async function setDockerNetworkPolicy(e,t,n){if(n!==`allow-all`&&n!==`deny-all`)throw Error(`The local Docker sandbox provider supports only the "allow-all" and "deny-all" network policies. Domain-level allow-lists and credential brokering require the Vercel provider (VercelSandbox) or MicrosandboxSandbox.`);let r=await e.run([`container`,`inspect`,`--format`,`{{json .NetworkSettings.Networks}}`,t]);expectDockerSuccess(r,`inspect networks of sandbox container "${t}"`);let i=JSON.parse(r.stdout.trim()===``?`{}`:r.stdout);if(typeof i!=`object`||!i)throw Error(`Docker returned invalid network settings for "${t}".`);let a=Object.keys(i);if(n===`deny-all`){for(let n of a)expectDockerSuccess(await e.run([`network`,`disconnect`,`--force`,n,t]),`disconnect sandbox container "${t}" from network "${n}"`);return}a.includes(`bridge`)||(a.includes(`none`)&&expectDockerSuccess(await e.run([`network`,`disconnect`,`--force`,`none`,t]),`detach sandbox container "${t}" from the none network`),expectDockerSuccess(await e.run([`network`,`connect`,`bridge`,t]),`connect sandbox container "${t}" to the bridge network`))}export{setDockerNetworkPolicy};