@@ -223,6 +223,10 @@ export class Sandbox extends BaseSandbox {
223223 const headers : Record < string , string > = {
224224 'Content-Type' : 'application/json' ,
225225 }
226+
227+ if ( this . trafficAccessToken ) {
228+ headers [ 'E2B-Traffic-Access-Token' ] = this . trafficAccessToken
229+ }
226230 if ( this . envdAccessToken ) {
227231 headers [ 'X-Access-Token' ] = this . envdAccessToken
228232 }
@@ -296,12 +300,17 @@ export class Sandbox extends BaseSandbox {
296300 */
297301 async createCodeContext ( opts ?: CreateCodeContextOpts ) : Promise < Context > {
298302 try {
303+ const headers : Record < string , string > = {
304+ 'Content-Type' : 'application/json' ,
305+ }
306+
307+ if ( this . trafficAccessToken ) {
308+ headers [ 'E2B-Traffic-Access-Token' ] = this . trafficAccessToken
309+ }
310+
299311 const res = await fetch ( `${ this . jupyterUrl } /contexts` , {
300312 method : 'POST' ,
301- headers : {
302- 'Content-Type' : 'application/json' ,
303- ...this . connectionConfig . headers ,
304- } ,
313+ headers,
305314 body : JSON . stringify ( {
306315 language : opts ?. language ,
307316 cwd : opts ?. cwd ,
@@ -331,12 +340,17 @@ export class Sandbox extends BaseSandbox {
331340 async removeCodeContext ( context : Context | string ) : Promise < void > {
332341 try {
333342 const id = typeof context === 'string' ? context : context . id
343+ const headers : Record < string , string > = {
344+ 'Content-Type' : 'application/json' ,
345+ }
346+
347+ if ( this . trafficAccessToken ) {
348+ headers [ 'E2B-Traffic-Access-Token' ] = this . trafficAccessToken
349+ }
350+
334351 const res = await fetch ( `${ this . jupyterUrl } /contexts/${ id } ` , {
335352 method : 'DELETE' ,
336- headers : {
337- 'Content-Type' : 'application/json' ,
338- ...this . connectionConfig . headers ,
339- } ,
353+ headers,
340354 keepalive : true ,
341355 signal : this . connectionConfig . getSignal (
342356 this . connectionConfig . requestTimeoutMs
@@ -359,12 +373,17 @@ export class Sandbox extends BaseSandbox {
359373 */
360374 async listCodeContexts ( ) : Promise < Context [ ] > {
361375 try {
376+ const headers : Record < string , string > = {
377+ 'Content-Type' : 'application/json' ,
378+ }
379+
380+ if ( this . trafficAccessToken ) {
381+ headers [ 'E2B-Traffic-Access-Token' ] = this . trafficAccessToken
382+ }
383+
362384 const res = await fetch ( `${ this . jupyterUrl } /contexts` , {
363385 method : 'GET' ,
364- headers : {
365- 'Content-Type' : 'application/json' ,
366- ...this . connectionConfig . headers ,
367- } ,
386+ headers,
368387 keepalive : true ,
369388 signal : this . connectionConfig . getSignal (
370389 this . connectionConfig . requestTimeoutMs
@@ -392,12 +411,17 @@ export class Sandbox extends BaseSandbox {
392411 async restartCodeContext ( context : Context | string ) : Promise < void > {
393412 try {
394413 const id = typeof context === 'string' ? context : context . id
414+ const headers : Record < string , string > = {
415+ 'Content-Type' : 'application/json' ,
416+ }
417+
418+ if ( this . trafficAccessToken ) {
419+ headers [ 'E2B-Traffic-Access-Token' ] = this . trafficAccessToken
420+ }
421+
395422 const res = await fetch ( `${ this . jupyterUrl } /contexts/${ id } /restart` , {
396423 method : 'POST' ,
397- headers : {
398- 'Content-Type' : 'application/json' ,
399- ...this . connectionConfig . headers ,
400- } ,
424+ headers,
401425 keepalive : true ,
402426 signal : this . connectionConfig . getSignal (
403427 this . connectionConfig . requestTimeoutMs
0 commit comments