@e2b/cli 1.0.6-docker-api.3 → 1.0.6-docker-api.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -78,7 +78,7 @@ ${r.message}`:A,L=[k,t,e].filter(Boolean).join(`
|
|
|
78
78
|
`;else throw new Error("There is no such converter: "+type);return a}else{var o="";return Object.keys(e).forEach(function(c,u,d){var p=eu[n||c];if(typeof p=="function")o+=Kr(p(n?e:e[c],Sr),1,t)+`
|
|
79
79
|
`;else throw new Error("There is no such converter: "+c)}),o}}Sr.async=function(e,t,n){return Promise.resolve().then(function(){if(t=t||"",typeof e=="string"||typeof e=="number")return Kr(e,1,t);var r=[];if(Array.isArray(e)){var i=e.map(function(o,c){return Promise.resolve().then(function(){return Sr.async(o,"",n)}).then(function(u){return Kr(u,1,t)}).then(function(u){r[c]=u})});return Promise.all(i).then(function(){return r.join(`
|
|
80
80
|
`)})}else{var a=Object.keys(e)[0],s=eu[n||a];if(typeof s=="function")return Promise.resolve().then(function(){return s(n?e:e[a],Sr)}).then(function(o){return Kr(o,1,t)+`
|
|
81
|
-
`});throw new Error("There is no such converter: "+a)}})};Sr.converters=eu;N2.exports=Sr});var kK={};fE(kK,{pkg:()=>Zc});module.exports=qw(kK);l();var I2=X(require("update-notifier"));l();var ME=X(xE(),1),{program:tW,createCommand:nW,createArgument:rW,createOption:iW,CommanderError:aW,InvalidArgumentError:sW,InvalidOptionArgumentError:oW,Command:Ne,Argument:lW,Option:Kn,Help:cW}=ME.default;var fu={};fE(fu,{author:()=>m9,bin:()=>D9,bugs:()=>p9,default:()=>R9,dependencies:()=>C9,description:()=>u9,devDependencies:()=>h9,engines:()=>N9,files:()=>b9,homepage:()=>d9,keywords:()=>g9,license:()=>_9,name:()=>c9,publishConfig:()=>f9,repository:()=>E9,scripts:()=>T9,sideEffects:()=>S9,version:()=>gu});var c9="@e2b/cli",gu="1.0.6-docker-api.
|
|
81
|
+
`});throw new Error("There is no such converter: "+a)}})};Sr.converters=eu;N2.exports=Sr});var kK={};fE(kK,{pkg:()=>Zc});module.exports=qw(kK);l();var I2=X(require("update-notifier"));l();var ME=X(xE(),1),{program:tW,createCommand:nW,createArgument:rW,createOption:iW,CommanderError:aW,InvalidArgumentError:sW,InvalidOptionArgumentError:oW,Command:Ne,Argument:lW,Option:Kn,Help:cW}=ME.default;var fu={};fE(fu,{author:()=>m9,bin:()=>D9,bugs:()=>p9,default:()=>R9,dependencies:()=>C9,description:()=>u9,devDependencies:()=>h9,engines:()=>N9,files:()=>b9,homepage:()=>d9,keywords:()=>g9,license:()=>_9,name:()=>c9,publishConfig:()=>f9,repository:()=>E9,scripts:()=>T9,sideEffects:()=>S9,version:()=>gu});var c9="@e2b/cli",gu="1.0.6-docker-api.5",u9="CLI for managing e2b sandbox templates",d9="https://e2b.dev",_9="MIT",m9={name:"FoundryLabs, Inc.",email:"hello@e2b.dev",url:"https://e2b.dev"},p9="https://github.com/e2b-dev/e2b/issues",E9={type:"git",url:"https://github.com/e2b-dev/e2b",directory:"packages/cli"},f9={access:"public"},g9=["e2b","ai-agents","agents","ai","code-interpreter","sandbox","code","cli","runtime","vm","nodejs","javascript","typescript"],S9=!1,T9={prepublishOnly:"pnpm build",build:"tsc --noEmit --skipLibCheck && tsup --minify",dev:"tsup --watch",test:"pnpm build && cd testground/demo-basic && ../../dist/index.js template build","check-deps":"knip","update-deps":"ncu -u && pnpm i","generate-api-reference":"./scripts/generate_api_ref.sh"},h9={"@types/command-exists":"^1.2.3","@types/inquirer":"^9.0.7","@types/json2md":"^1.5.4","@types/node":"^18.18.6","@types/update-notifier":"6.0.5",json2md:"^2.0.1",knip:"^2.33.4","npm-check-updates":"^16.14.6",tsup:"^7.2.0",typescript:"^5.2.2"},b9=["dist","LICENSE","README","package.json"],D9={e2b:"dist/index.js"},C9={"@iarna/toml":"^2.2.5","async-listen":"^3.0.1",boxen:"^7.1.1",chalk:"^5.3.0","cli-highlight":"^2.1.11","command-exists":"^1.2.9",commander:"^11.1.0","console-table-printer":"^2.11.2",e2b:"^1.0.1",inquirer:"^9.2.12",open:"^9.1.0","strip-ansi":"^7.1.0","update-notifier":"5.1.0",yup:"^1.3.2"},N9={node:">=18"},R9={name:c9,version:gu,description:u9,homepage:d9,license:_9,author:m9,bugs:p9,repository:E9,publishConfig:f9,keywords:g9,sideEffects:S9,scripts:T9,devDependencies:h9,files:b9,bin:D9,dependencies:C9,engines:N9};l();l();l();l();var wE=(e=0)=>t=>`\x1B[${t+e}m`,LE=(e=0)=>t=>`\x1B[${38+e};5;${t}m`,PE=(e=0)=>(t,n,r)=>`\x1B[${38+e};2;${t};${n};${r}m`,Ue={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},dW=Object.keys(Ue.modifier),A9=Object.keys(Ue.color),O9=Object.keys(Ue.bgColor),_W=[...A9,...O9];function y9(){let e=new Map;for(let[t,n]of Object.entries(Ue)){for(let[r,i]of Object.entries(n))Ue[r]={open:`\x1B[${i[0]}m`,close:`\x1B[${i[1]}m`},n[r]=Ue[r],e.set(i[0],i[1]);Object.defineProperty(Ue,t,{value:n,enumerable:!1})}return Object.defineProperty(Ue,"codes",{value:e,enumerable:!1}),Ue.color.close="\x1B[39m",Ue.bgColor.close="\x1B[49m",Ue.color.ansi=wE(),Ue.color.ansi256=LE(),Ue.color.ansi16m=PE(),Ue.bgColor.ansi=wE(10),Ue.bgColor.ansi256=LE(10),Ue.bgColor.ansi16m=PE(10),Object.defineProperties(Ue,{rgbToAnsi256:{value(t,n,r){return t===n&&n===r?t<8?16:t>248?231:Math.round((t-8)/247*24)+232:16+36*Math.round(t/255*5)+6*Math.round(n/255*5)+Math.round(r/255*5)},enumerable:!1},hexToRgb:{value(t){let n=/[a-f\d]{6}|[a-f\d]{3}/i.exec(t.toString(16));if(!n)return[0,0,0];let[r]=n;r.length===3&&(r=[...r].map(a=>a+a).join(""));let i=Number.parseInt(r,16);return[i>>16&255,i>>8&255,i&255]},enumerable:!1},hexToAnsi256:{value:t=>Ue.rgbToAnsi256(...Ue.hexToRgb(t)),enumerable:!1},ansi256ToAnsi:{value(t){if(t<8)return 30+t;if(t<16)return 90+(t-8);let n,r,i;if(t>=232)n=((t-232)*10+8)/255,r=n,i=n;else{t-=16;let o=t%36;n=Math.floor(t/36)/5,r=Math.floor(o/6)/5,i=o%6/5}let a=Math.max(n,r,i)*2;if(a===0)return 30;let s=30+(Math.round(i)<<2|Math.round(r)<<1|Math.round(n));return a===2&&(s+=60),s},enumerable:!1},rgbToAnsi:{value:(t,n,r)=>Ue.ansi256ToAnsi(Ue.rgbToAnsi256(t,n,r)),enumerable:!1},hexToAnsi:{value:t=>Ue.ansi256ToAnsi(Ue.hexToAnsi256(t)),enumerable:!1}}),Ue}var I9=y9(),nn=I9;l();var ws=X(require("process"),1),kE=X(require("os"),1),Su=X(require("tty"),1);function qt(e,t=globalThis.Deno?globalThis.Deno.args:ws.default.argv){let n=e.startsWith("-")?"":e.length===1?"-":"--",r=t.indexOf(n+e),i=t.indexOf("--");return r!==-1&&(i===-1||r<i)}var{env:qe}=ws.default,Ms;qt("no-color")||qt("no-colors")||qt("color=false")||qt("color=never")?Ms=0:(qt("color")||qt("colors")||qt("color=true")||qt("color=always"))&&(Ms=1);function v9(){if("FORCE_COLOR"in qe)return qe.FORCE_COLOR==="true"?1:qe.FORCE_COLOR==="false"?0:qe.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(qe.FORCE_COLOR,10),3)}function x9(e){return e===0?!1:{level:e,hasBasic:!0,has256:e>=2,has16m:e>=3}}function M9(e,{streamIsTTY:t,sniffFlags:n=!0}={}){let r=v9();r!==void 0&&(Ms=r);let i=n?Ms:r;if(i===0)return 0;if(n){if(qt("color=16m")||qt("color=full")||qt("color=truecolor"))return 3;if(qt("color=256"))return 2}if("TF_BUILD"in qe&&"AGENT_NAME"in qe)return 1;if(e&&!t&&i===void 0)return 0;let a=i||0;if(qe.TERM==="dumb")return a;if(ws.default.platform==="win32"){let s=kE.default.release().split(".");return Number(s[0])>=10&&Number(s[2])>=10586?Number(s[2])>=14931?3:2:1}if("CI"in qe)return"GITHUB_ACTIONS"in qe||"GITEA_ACTIONS"in qe?3:["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(s=>s in qe)||qe.CI_NAME==="codeship"?1:a;if("TEAMCITY_VERSION"in qe)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(qe.TEAMCITY_VERSION)?1:0;if(qe.COLORTERM==="truecolor"||qe.TERM==="xterm-kitty")return 3;if("TERM_PROGRAM"in qe){let s=Number.parseInt((qe.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(qe.TERM_PROGRAM){case"iTerm.app":return s>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(qe.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(qe.TERM)||"COLORTERM"in qe?1:a}function FE(e,t={}){let n=M9(e,{streamIsTTY:e&&e.isTTY,...t});return x9(n)}var w9={stdout:FE({isTTY:Su.default.isatty(1)}),stderr:FE({isTTY:Su.default.isatty(2)})},BE=w9;l();function UE(e,t,n){let r=e.indexOf(t);if(r===-1)return e;let i=t.length,a=0,s="";do s+=e.slice(a,r)+t+n,a=r+i,r=e.indexOf(t,a);while(r!==-1);return s+=e.slice(a),s}function GE(e,t,n,r){let i=0,a="";do{let s=e[r-1]==="\r";a+=e.slice(i,s?r-1:r)+t+(s?`\r
|
|
82
82
|
`:`
|
|
83
83
|
`)+n,i=r+1,r=e.indexOf(`
|
|
84
84
|
`,i)}while(r!==-1);return a+=e.slice(i),a}var{stdout:HE,stderr:YE}=BE,Tu=Symbol("GENERATOR"),Wr=Symbol("STYLER"),ia=Symbol("IS_EMPTY"),VE=["ansi","ansi","ansi256","ansi16m"],zr=Object.create(null),L9=(e,t={})=>{if(t.level&&!(Number.isInteger(t.level)&&t.level>=0&&t.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let n=HE?HE.level:0;e.level=t.level===void 0?n:t.level};var P9=e=>{let t=(...n)=>n.join(" ");return L9(t,e),Object.setPrototypeOf(t,aa.prototype),t};function aa(e){return P9(e)}Object.setPrototypeOf(aa.prototype,Function.prototype);for(let[e,t]of Object.entries(nn))zr[e]={get(){let n=Ls(this,bu(t.open,t.close,this[Wr]),this[ia]);return Object.defineProperty(this,e,{value:n}),n}};zr.visible={get(){let e=Ls(this,this[Wr],!0);return Object.defineProperty(this,"visible",{value:e}),e}};var hu=(e,t,n,...r)=>e==="rgb"?t==="ansi16m"?nn[n].ansi16m(...r):t==="ansi256"?nn[n].ansi256(nn.rgbToAnsi256(...r)):nn[n].ansi(nn.rgbToAnsi(...r)):e==="hex"?hu("rgb",t,n,...nn.hexToRgb(...r)):nn[n][e](...r),F9=["rgb","hex","ansi256"];for(let e of F9){zr[e]={get(){let{level:n}=this;return function(...r){let i=bu(hu(e,VE[n],"color",...r),nn.color.close,this[Wr]);return Ls(this,i,this[ia])}}};let t="bg"+e[0].toUpperCase()+e.slice(1);zr[t]={get(){let{level:n}=this;return function(...r){let i=bu(hu(e,VE[n],"bgColor",...r),nn.bgColor.close,this[Wr]);return Ls(this,i,this[ia])}}}}var k9=Object.defineProperties(()=>{},{...zr,level:{enumerable:!0,get(){return this[Tu].level},set(e){this[Tu].level=e}}}),bu=(e,t,n)=>{let r,i;return n===void 0?(r=e,i=t):(r=n.openAll+e,i=t+n.closeAll),{open:e,close:t,openAll:r,closeAll:i,parent:n}},Ls=(e,t,n)=>{let r=(...i)=>B9(r,i.length===1?""+i[0]:i.join(" "));return Object.setPrototypeOf(r,k9),r[Tu]=e,r[Wr]=t,r[ia]=n,r},B9=(e,t)=>{if(e.level<=0||!t)return e[ia]?"":t;let n=e[Wr];if(n===void 0)return t;let{openAll:r,closeAll:i}=n;if(t.includes("\x1B"))for(;n!==void 0;)t=UE(t,n.close,n.open),n=n.parent;let a=t.indexOf(`
|
|
@@ -117,10 +117,10 @@ attempted value: ${s}
|
|
|
117
117
|
# import { Sandbox } from 'e2b'
|
|
118
118
|
# const sandbox = await Sandbox.create('${e.template_name||e.template_id}')
|
|
119
119
|
|
|
120
|
-
`}var gI=vm({template_id:Ur().required(),template_name:Ur().optional(),dockerfile:Ur().required(),start_cmd:Ur().optional(),cpu_count:oc().integer().min(1).optional(),memory_mb:oc().integer().min(128).optional(),team_id:Ur().optional()}),cY=[{from:"id",to:"template_id"},{from:"name",to:"template_name"}];function uY(e,t){for(let n of t){let r=n.from,i=n.to;e[r]&&(e[i]=e[r],delete e[r])}return e}async function ki(e){let t=await Pi.readFile(e,"utf-8"),n=Ec.parse(t),r=uY(n,cY);return await gI.validate(r)}async function SI(e,t,n){try{if(!n&&fI.existsSync(e))throw new Error(`Config already exists on path ${Dt(e)}`);let r=await gI.validate(t,{stripUnknown:!0}),i=Ec.stringify(r);await Pi.writeFile(e,lY(t)+i)}catch(r){throw new Error(`E2B sandbox template config ${ft({templateID:t.template_id},e)} cannot be saved: ${r.message}`)}}async function TI(e){await Pi.unlink(e)}function Bi(e,t){return t&&fc.isAbsolute(t)?t:fc.join(e,t||Fi)}var Sc=X(require("child_process"));l();var Bm=class extends Error{constructor(t){super(t),this.name="E2BRequestError"}};function Nt(e,t){if(!e)return;let n="";switch(e.code){case 400:n="bad request";break;case 401:n="unauthorized";break;case 403:n="forbidden";break;case 404:n="not found";break;case 500:n="internal server error";break}throw new Bm(`${t&&`${t}: `}[${e.code}] ${n&&`${n}: `}${e.message??"no message"}`)}l();var Um=X(require("child_process")),hI=X(require("http")),bI=require("url"),DI=X(require("https")),gc=49984;async function CI(e,t,n,r){console.log("Here should be some instructions what to do, probably link to docs. Also check if already configured, if yes skip this step.");let i,a=new Promise(c=>{i=c}),s=Buffer.from(`_e2b_access_token:${t}`).toString("base64"),o=await _Y(e,n,s,i);await a,await dY(e,n,r),o.close()}async function dY(e,t,n){let r=process.platform==="linux"?"localhost":"host.docker.internal";Um.default.execSync(`docker tag docker.${e.domain}/e2b/custom-envs/${t.templateID}:${t.buildID} ${r}:${gc}/e2b/custom-envs/${t.templateID}:${t.buildID}`,{stdio:"inherit",cwd:n});let i,a=new Promise(o=>{i=o}),s=Um.default.spawn("docker",["push",`${r}:${gc}/e2b/custom-envs/${t.templateID}:${t.buildID}`],{detached:!0,stdio:"inherit",cwd:n});s.on("exit",o=>{o!==0&&(console.error("Docker push failed"),process.exit(1)),i(o)}),s.on("error",o=>{console.error("Error",o),process.exit(1)}),await a}async function _Y(e,t,n,r){let i=await fetch(`https://docker.${e.domain}/v2/token?account=_e2b_access_token&scope=repository%3Ae2b%2Fcustom-envs%2F${t.templateID}%3Apush%2Cpull`,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Basic ${n}`}}),{token:a}=await i.json(),s=hI.createServer((o,c)=>{let u=new bI.URL(o.url||"/",`https://docker.${e.domain}`),d={protocol:"https:",hostname:u.hostname,method:o.method,path:u.pathname+u.search,headers:{...o.headers,host:u.hostname}};d.headers.Authorization||(u.pathname.startsWith("/v2/token")?d.headers.Authorization=`Basic ${n}`:u.pathname=="/v2/"||u.pathname=="/v2"?d.headers.Authorization=`Bearer ${n}`:d.headers.Authorization=`Bearer ${a}`);let p=DI.request(d,S=>{c.writeHead(S.statusCode||500,S.headers),S.pipe(c,{end:!0})});p.on("error",S=>{console.error("Proxy Request Error:",S),c.statusCode=500,c.end(`Proxy Error: ${S.message}`)}),o.pipe(p,{end:!0})});return s.on("error",o=>{console.error("Server Error:",o)}),s.listen(gc,()=>{r(null),console.log(`Proxy server running on port ${gc}`)}),s}var mY=500;async function pY({templateID:e,buildID:t,logsOffset:n}){let r=vt.getSignal(),i=await xt.api.GET("/templates/{templateID}/builds/{buildID}/status",{signal:r,params:{path:{templateID:e,buildID:t},query:{logsOffset:n}}});return Nt(i.error,"Error getting template build status"),i.data}async function EY(e){return await xt.api.POST("/templates",{body:e})}async function fY(e,t){return await xt.api.POST("/templates/{templateID}",{body:t,params:{path:{templateID:e}}})}async function gY(e,t){let n=await xt.api.POST("/templates/{templateID}/builds/{buildID}",{params:{path:{templateID:e,buildID:t}}});return Nt(n.error,"Error triggering template build"),n.data}var RI=new Ne("build").description(`build sandbox template defined by ${Dt(_r)} or ${Dt($l)} in root directory. By default the root directory is the current working directory. This command also creates ${Ft(Fi)} config.`).argument("[template]",`specify ${_e("[template]")} to rebuild it. If you don's specify ${_e("[template]")} and there is no ${Ft("e2b.toml")} a new sandbox template will be created.`).addOption(dr).option("-d, --dockerfile <file>",`specify path to Dockerfile. By default E2B tries to find ${Ft(_r)} or ${Ft($l)} in root directory.`).option("-n, --name <template-name>","specify sandbox template name. You can use the template name to start the sandbox with SDK. The template name must be lowercase and contain only letters, numbers, dashes and underscores.").option("-c, --cmd <start-command>","specify command that will be executed when the sandbox is started.").addOption(xi).addOption(vi).option("--cpu-count <cpu-count>","specify the number of CPUs that will be used to run the sandbox. The default value is 2.",parseInt).option("--memory-mb <memory-mb>","specify the amount of memory in megabytes that will be used to run the sandbox. Must be an even number. The default value is 512.",parseInt).option("--build-arg <args...>","specify additional build arguments for the build command. The format should be <varname>=<value>.").alias("bd").action(async(e,t)=>{try{NI.default.sync("docker")||(console.error("Docker is required to build and push the sandbox template. Please install Docker and try again."),process.exit(1));let r={};t.buildArg&&t.buildArg.forEach(Q=>{let[ie,w]=Q.split("=");r[ie]=w});let i=Ii();process.stdout.write(`
|
|
120
|
+
`}var gI=vm({template_id:Ur().required(),template_name:Ur().optional(),dockerfile:Ur().required(),start_cmd:Ur().optional(),cpu_count:oc().integer().min(1).optional(),memory_mb:oc().integer().min(128).optional(),team_id:Ur().optional()}),cY=[{from:"id",to:"template_id"},{from:"name",to:"template_name"}];function uY(e,t){for(let n of t){let r=n.from,i=n.to;e[r]&&(e[i]=e[r],delete e[r])}return e}async function ki(e){let t=await Pi.readFile(e,"utf-8"),n=Ec.parse(t),r=uY(n,cY);return await gI.validate(r)}async function SI(e,t,n){try{if(!n&&fI.existsSync(e))throw new Error(`Config already exists on path ${Dt(e)}`);let r=await gI.validate(t,{stripUnknown:!0}),i=Ec.stringify(r);await Pi.writeFile(e,lY(t)+i)}catch(r){throw new Error(`E2B sandbox template config ${ft({templateID:t.template_id},e)} cannot be saved: ${r.message}`)}}async function TI(e){await Pi.unlink(e)}function Bi(e,t){return t&&fc.isAbsolute(t)?t:fc.join(e,t||Fi)}var Sc=X(require("child_process"));l();var Bm=class extends Error{constructor(t){super(t),this.name="E2BRequestError"}};function Nt(e,t){if(!e)return;let n="";switch(e.code){case 400:n="bad request";break;case 401:n="unauthorized";break;case 403:n="forbidden";break;case 404:n="not found";break;case 500:n="internal server error";break}throw new Bm(`${t&&`${t}: `}[${e.code}] ${n&&`${n}: `}${e.message??"no message"}`)}l();var Um=X(require("child_process")),hI=X(require("http")),bI=require("url"),DI=X(require("https")),gc=49984;async function CI(e,t,n,r){console.log("Here should be some instructions what to do, probably link to docs. Also check if already configured, if yes skip this step.");let i,a=new Promise(c=>{i=c}),s=Buffer.from(`_e2b_access_token:${t}`).toString("base64"),o=await _Y(e,n,s,i);await a,await dY(e,n,r),o.close()}async function dY(e,t,n){let r=process.platform==="linux"?"localhost":"host.docker.internal";Um.default.execSync(`docker tag docker.${e.domain}/e2b/custom-envs/${t.templateID}:${t.buildID} ${r}:${gc}/e2b/custom-envs/${t.templateID}:${t.buildID}`,{stdio:"inherit",cwd:n});let i,a=new Promise(o=>{i=o}),s=Um.default.spawn("docker",["push",`${r}:${gc}/e2b/custom-envs/${t.templateID}:${t.buildID}`],{detached:!0,stdio:"inherit",cwd:n});s.on("exit",o=>{o!==0&&(console.error("Docker push failed"),process.exit(1)),i(o)}),s.on("error",o=>{console.error("Error",o),process.exit(1)}),await a}async function _Y(e,t,n,r){let i=await fetch(`https://docker.${e.domain}/v2/token?account=_e2b_access_token&scope=repository%3Ae2b%2Fcustom-envs%2F${t.templateID}%3Apush%2Cpull`,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Basic ${n}`}}),{token:a}=await i.json(),s=hI.createServer((o,c)=>{let u=new bI.URL(o.url||"/",`https://docker.${e.domain}`),d={protocol:"https:",hostname:u.hostname,method:o.method,path:u.pathname+u.search,headers:{...o.headers,host:u.hostname}};d.headers.Authorization||(u.pathname.startsWith("/v2/token")?d.headers.Authorization=`Basic ${n}`:u.pathname=="/v2/"||u.pathname=="/v2"?d.headers.Authorization=`Bearer ${n}`:u.pathname.startsWith("/artifacts-uploads/namespaces")||(d.headers.Authorization=`Bearer ${a}`));let p=DI.request(d,S=>{c.writeHead(S.statusCode||500,S.headers),S.pipe(c,{end:!0})});p.on("error",S=>{console.error("Proxy Request Error:",S),c.statusCode=500,c.end(`Proxy Error: ${S.message}`)}),o.pipe(p,{end:!0})});return s.on("error",o=>{console.error("Server Error:",o)}),s.listen(gc,()=>{r(null),console.log(`Proxy server running on port ${gc}`)}),s}var mY=500;async function pY({templateID:e,buildID:t,logsOffset:n}){let r=vt.getSignal(),i=await xt.api.GET("/templates/{templateID}/builds/{buildID}/status",{signal:r,params:{path:{templateID:e,buildID:t},query:{logsOffset:n}}});return Nt(i.error,"Error getting template build status"),i.data}async function EY(e){return await xt.api.POST("/templates",{body:e})}async function fY(e,t){return await xt.api.POST("/templates/{templateID}",{body:t,params:{path:{templateID:e}}})}async function gY(e,t){let n=await xt.api.POST("/templates/{templateID}/builds/{buildID}",{params:{path:{templateID:e,buildID:t}}});return Nt(n.error,"Error triggering template build"),n.data}var RI=new Ne("build").description(`build sandbox template defined by ${Dt(_r)} or ${Dt($l)} in root directory. By default the root directory is the current working directory. This command also creates ${Ft(Fi)} config.`).argument("[template]",`specify ${_e("[template]")} to rebuild it. If you don's specify ${_e("[template]")} and there is no ${Ft("e2b.toml")} a new sandbox template will be created.`).addOption(dr).option("-d, --dockerfile <file>",`specify path to Dockerfile. By default E2B tries to find ${Ft(_r)} or ${Ft($l)} in root directory.`).option("-n, --name <template-name>","specify sandbox template name. You can use the template name to start the sandbox with SDK. The template name must be lowercase and contain only letters, numbers, dashes and underscores.").option("-c, --cmd <start-command>","specify command that will be executed when the sandbox is started.").addOption(xi).addOption(vi).option("--cpu-count <cpu-count>","specify the number of CPUs that will be used to run the sandbox. The default value is 2.",parseInt).option("--memory-mb <memory-mb>","specify the amount of memory in megabytes that will be used to run the sandbox. Must be an even number. The default value is 512.",parseInt).option("--build-arg <args...>","specify additional build arguments for the build command. The format should be <varname>=<value>.").alias("bd").action(async(e,t)=>{try{NI.default.sync("docker")||(console.error("Docker is required to build and push the sandbox template. Please install Docker and try again."),process.exit(1));let r={};t.buildArg&&t.buildArg.forEach(Q=>{let[ie,w]=Q.split("=");r[ie]=w});let i=Ii();process.stdout.write(`
|
|
121
121
|
`);let a=t.name?.trim();a&&!/[a-z0-9-_]+/.test(a)&&(console.error(`Name ${Ft(a)} is not valid. Name can only contain lowercase letters, numbers, dashes and underscores.`),process.exit(1));let s=t.dockerfile,o=t.cmd,c=t.cpuCount,u=t.memoryMb,d=t.team,p=sr(t.path),S=Bi(p,t.config),g=ls.existsSync(S)?await ki(S):void 0,T=Vn.relative(p,S);g&&(console.log(`Found sandbox template ${ft({templateID:g.template_id,aliases:g.template_name?[g.template_name]:void 0},T)}`),e=g.template_id,s=t.dockerfile||g.dockerfile,o=t.cmd||g.start_cmd,c=t.cpuCount||g.cpu_count,u=t.memoryMb||g.memory_mb,d=t.team||g.team_id);let A=Ht();A&&(d=d||A.teamId),g&&e&&g.template_id!==e&&(console.error("You can't specify different ID than the one in config. If you want to build a new sandbox template remove the config file."),process.exit(1)),a&&g?.template_name&&a!==g?.template_name&&console.log(`The sandbox template name will be changed from ${Ft(g.template_name)} to ${Ft(a)}.`);let v=a||g?.template_name,{dockerfileContent:k,dockerfileRelativePath:L}=TY(p,s);console.log(`Found ${Dt(L)} that will be used to build the sandbox template.`);let B={alias:v,startCmd:o,cpuCount:c,memoryMB:u,dockerfile:k,teamID:d};t.memoryMb&&t.memoryMb%2!==0&&(console.error(`The memory in megabytes must be an even number. You provided ${Ft(t.memoryMb.toFixed(0))}.`),process.exit(1));let H=await hY(B,e);e=H.templateID,console.log(`Requested build for the sandbox template ${ft(H)} `),await SI(S,{template_id:H.templateID,dockerfile:L,template_name:v,start_cmd:o,cpu_count:c,memory_mb:u,team_id:d},!0);try{Sc.execSync(`echo "${i}" | docker login docker.${vt.domain} -u _e2b_access_token --password-stdin`,{stdio:"inherit",cwd:p})}catch{console.error("Docker login failed. Please try to log in with `e2b auth login` and try again."),process.exit(1)}process.stdout.write(`
|
|
122
122
|
`),console.log("Building docker image...");let ne=`docker build . -f ${L} --pull --platform linux/amd64 -t docker.${vt.domain}/e2b/custom-envs/${e}:${H.buildID} ${Object.entries(r).map(([Q,ie])=>`--build-arg="${Q}=${ie}"`).join(" ")}`;Sc.execSync(ne,{stdio:"inherit",cwd:p,env:{...process.env,DOCKER_CLI_HINTS:"false"}}),console.log(`Docker image built.
|
|
123
|
-
`),console.log("Pushing docker image...");try{
|
|
123
|
+
`),console.log("Pushing docker image...");try{Sc.execSync(`docker push docker.${vt.domain}/e2b/custom-envs/${e}:${H.buildID}`,{stdio:"inherit",cwd:p})}catch{await CI(vt,i,H,p)}console.log(`Docker image pushed.
|
|
124
124
|
`),console.log("Triggering build..."),await bY(e,H.buildID),console.log(`Triggered build for the sandbox template ${ft(H)} `),console.log("Waiting for build to finish..."),await SY(e,H.buildID,v),process.exit(0)}catch(n){console.error(n),process.exit(1)}});async function SY(e,t,n){let r=0,i,a=n?[n]:void 0;process.stdout.write(`
|
|
125
125
|
`);do switch(await wa(mY),i=await pY({templateID:e,logsOffset:r,buildID:t}),r+=i.logs.length,i.status){case"building":i.logs.forEach(s=>process.stdout.write(d_(rr(s))));break;case"ready":{let s=qR(`from e2b import Sandbox, AsyncSandbox
|
|
126
126
|
|