eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 1.11 kB
JavaScript
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 backend supports only the "allow-all" and "deny-all" network policies. Domain-level allow-lists and credential brokering require the Vercel backend (vercel()) or microsandbox().`);let r=await e.run([`container`,`inspect`,`--format`,`{{json .NetworkSettings.Networks}}`,t]);expectDockerSuccess(r,`inspect networks of sandbox container "${t}"`);let i=Object.keys(JSON.parse(r.stdout.trim()===``?`{}`:r.stdout));if(n===`deny-all`){for(let n of i)expectDockerSuccess(await e.run([`network`,`disconnect`,`--force`,n,t]),`disconnect sandbox container "${t}" from network "${n}"`);return}i.includes(`bridge`)||(i.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};