@@ -123,9 +123,15 @@ export class Sandbox extends SandboxApi {
123123 this . sandboxDomain = opts . sandboxDomain ?? this . connectionConfig . domain
124124
125125 this . envdAccessToken = opts . envdAccessToken
126- this . envdApiUrl = `${
127- this . connectionConfig . debug ? 'http' : 'https'
128- } ://${ this . getHost ( this . envdPort ) } `
126+ this . envdApiUrl = this . connectionConfig . getSandboxUrl ( this . sandboxId , {
127+ sandboxDomain : this . sandboxDomain ,
128+ envdPort : this . envdPort
129+ } )
130+
131+ const sandboxHeaders = {
132+ 'E2b-Sandbox-Id' : this . sandboxId ,
133+ 'E2b-Sandbox-Port' : this . envdPort . toString ( ) ,
134+ }
129135
130136 const rpcTransport = createConnectTransport ( {
131137 baseUrl : this . envdApiUrl ,
@@ -141,6 +147,9 @@ export class Sandbox extends SandboxApi {
141147 new Headers ( options ?. headers ) . forEach ( ( value , key ) =>
142148 headers . append ( key , value )
143149 )
150+ new Headers ( sandboxHeaders ) . forEach ( ( value , key ) =>
151+ headers . append ( key , value )
152+ )
144153
145154 if ( this . envdAccessToken ) {
146155 headers . append ( 'X-Access-Token' , this . envdAccessToken )
@@ -238,15 +247,15 @@ export class Sandbox extends SandboxApi {
238247 const { template, sandboxOpts } =
239248 typeof templateOrOpts === 'string'
240249 ? {
241- template : templateOrOpts ,
242- sandboxOpts : opts ,
243- }
250+ template : templateOrOpts ,
251+ sandboxOpts : opts ,
252+ }
244253 : {
245- template : templateOrOpts ?. mcp
246- ? this . defaultMcpTemplate
247- : this . defaultTemplate ,
248- sandboxOpts : templateOrOpts ,
249- }
254+ template : templateOrOpts ?. mcp
255+ ? this . defaultMcpTemplate
256+ : this . defaultTemplate ,
257+ sandboxOpts : templateOrOpts ,
258+ }
250259
251260 const config = new ConnectionConfig ( sandboxOpts )
252261 if ( config . debug ) {
@@ -333,15 +342,15 @@ export class Sandbox extends SandboxApi {
333342 const { template, sandboxOpts } =
334343 typeof templateOrOpts === 'string'
335344 ? {
336- template : templateOrOpts ,
337- sandboxOpts : opts ,
338- }
345+ template : templateOrOpts ,
346+ sandboxOpts : opts ,
347+ }
339348 : {
340- template : templateOrOpts ?. mcp
341- ? this . defaultMcpTemplate
342- : this . defaultTemplate ,
343- sandboxOpts : templateOrOpts ,
344- }
349+ template : templateOrOpts ?. mcp
350+ ? this . defaultMcpTemplate
351+ : this . defaultTemplate ,
352+ sandboxOpts : templateOrOpts ,
353+ }
345354
346355 const config = new ConnectionConfig ( sandboxOpts )
347356 if ( config . debug ) {
@@ -482,11 +491,7 @@ export class Sandbox extends SandboxApi {
482491 * ```
483492 */
484493 getHost ( port : number ) {
485- if ( this . connectionConfig . debug ) {
486- return `localhost:${ port } `
487- }
488-
489- return `${ port } -${ this . sandboxId } .${ this . sandboxDomain } `
494+ return this . connectionConfig . getHost ( this . sandboxId , port , this . sandboxDomain )
490495 }
491496
492497 /**
@@ -732,7 +737,7 @@ export class Sandbox extends SandboxApi {
732737 if ( compareVersions ( this . envdApi . version , '0.1.5' ) < 0 ) {
733738 throw new SandboxError (
734739 'You need to update the template to use the new SDK. ' +
735- 'You can do this by running `e2b template build` in the directory with the template.'
740+ 'You can do this by running `e2b template build` in the directory with the template.'
736741 )
737742 }
738743
0 commit comments