File tree Expand file tree Collapse file tree 5 files changed +37
-22
lines changed
Expand file tree Collapse file tree 5 files changed +37
-22
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { asBold, asPrimary } from './utils/format'
66
77export let apiKey = process . env . E2B_API_KEY
88export let accessToken = process . env . E2B_ACCESS_TOKEN
9+ export const teamId = process . env . E2B_TEAM_ID
910
1011const authErrorBox = ( keyName : string ) => {
1112 let link
@@ -82,6 +83,28 @@ export function ensureAccessToken() {
8283 }
8384}
8485
86+ /**
87+ * Resolve team ID with proper precedence:
88+ * 1. CLI --team flag
89+ * 2. E2B_TEAM_ID env var
90+ * 3. Local e2b.toml team_id (if provided)
91+ * 4. ~/.e2b/config.json teamId (only if E2B_API_KEY env var is NOT set,
92+ * to avoid mismatch between env var API key and config file team ID)
93+ */
94+ export function resolveTeamId (
95+ cliTeamId ?: string ,
96+ localConfigTeamId ?: string
97+ ) : string | undefined {
98+ if ( cliTeamId ) return cliTeamId
99+ if ( teamId ) return teamId
100+ if ( localConfigTeamId ) return localConfigTeamId
101+ if ( ! process . env . E2B_API_KEY ) {
102+ const config = getUserConfig ( )
103+ return config ?. teamId
104+ }
105+ return undefined
106+ }
107+
85108const userConfig = getUserConfig ( )
86109
87110export const connectionConfig = new e2b . ConnectionConfig ( {
Original file line number Diff line number Diff line change @@ -5,7 +5,12 @@ import * as commander from 'commander'
55import * as e2b from 'e2b'
66import * as fs from 'fs'
77import * as path from 'path'
8- import { client , connectionConfig , ensureAccessToken } from 'src/api'
8+ import {
9+ client ,
10+ connectionConfig ,
11+ ensureAccessToken ,
12+ resolveTeamId ,
13+ } from 'src/api'
914import { configName , getConfigPath , loadConfig , saveConfig } from 'src/config'
1015import {
1116 defaultDockerfileName ,
@@ -288,13 +293,9 @@ Migration guide: ${asPrimary('https://e2b.dev/docs/template/migration-v2')}`
288293 readyCmd = opts . readyCmd || config . ready_cmd
289294 cpuCount = opts . cpuCount || config . cpu_count
290295 memoryMB = opts . memoryMb || config . memory_mb
291- teamID = opts . team || config . team_id
292296 }
293297
294- const userConfig = getUserConfig ( )
295- if ( userConfig ) {
296- teamID = teamID || userConfig . teamId
297- }
298+ teamID = resolveTeamId ( opts . team , config ?. team_id )
298299
299300 if ( config && templateID && config . template_id !== templateID ) {
300301 // error: you can't specify different ID than the one in config
@@ -444,6 +445,7 @@ Migration guide: ${asPrimary('https://e2b.dev/docs/template/migration-v2')}`
444445 cwd : root ,
445446 } )
446447 } catch ( err : any ) {
448+ const userConfig = getUserConfig ( )
447449 await buildWithProxy (
448450 userConfig ,
449451 connectionConfig ,
Original file line number Diff line number Diff line change @@ -26,9 +26,8 @@ import { getRoot } from 'src/utils/filesystem'
2626import { listSandboxTemplates } from './list'
2727import { getPromptTemplates } from 'src/utils/templatePrompt'
2828import { confirm } from 'src/utils/confirm'
29- import { client } from 'src/api'
29+ import { client , resolveTeamId } from 'src/api'
3030import { handleE2BRequestError } from '../../utils/errors'
31- import { getUserConfig } from 'src/user'
3231
3332async function deleteTemplate ( templateID : string ) {
3433 const res = await client . api . DELETE ( '/templates/{templateID}' , {
@@ -84,10 +83,7 @@ export const deleteCommand = new commander.Command('delete')
8483 template_id : template ,
8584 } )
8685 } else if ( opts . select ) {
87- const userConfig = getUserConfig ( )
88- if ( userConfig ) {
89- teamId = teamId || userConfig . teamId
90- }
86+ teamId = resolveTeamId ( teamId )
9187
9288 const allTemplates = await listSandboxTemplates ( {
9389 teamID : teamId ,
Original file line number Diff line number Diff line change @@ -4,10 +4,9 @@ import * as e2b from 'e2b'
44
55import { listAliases } from '../../utils/format'
66import { sortTemplatesAliases } from 'src/utils/templateSort'
7- import { client , ensureAccessToken } from 'src/api'
7+ import { client , ensureAccessToken , resolveTeamId } from 'src/api'
88import { teamOption } from '../../options'
99import { handleE2BRequestError } from '../../utils/errors'
10- import { getUserConfig } from '../../user'
1110
1211export const listCommand = new commander . Command ( 'list' )
1312 . description ( 'list sandbox templates' )
@@ -17,12 +16,11 @@ export const listCommand = new commander.Command('list')
1716 . action ( async ( opts : { team : string ; format : string } ) => {
1817 try {
1918 const format = opts . format || 'pretty'
20- const userConfig = getUserConfig ( )
2119 ensureAccessToken ( )
2220 process . stdout . write ( '\n' )
2321
2422 const templates = await listSandboxTemplates ( {
25- teamID : opts . team || userConfig ?. teamId ,
23+ teamID : resolveTeamId ( opts . team ) ,
2624 } )
2725
2826 for ( const template of templates ) {
Original file line number Diff line number Diff line change @@ -20,9 +20,8 @@ import { getRoot } from 'src/utils/filesystem'
2020import { listSandboxTemplates } from './list'
2121import { getPromptTemplates } from 'src/utils/templatePrompt'
2222import { confirm } from 'src/utils/confirm'
23- import { client } from 'src/api'
23+ import { client , resolveTeamId } from 'src/api'
2424import { handleE2BRequestError } from '../../utils/errors'
25- import { getUserConfig } from 'src/user'
2625
2726async function publishTemplate ( templateID : string , publish : boolean ) {
2827 const res = await client . api . PATCH ( '/v2/templates/{templateID}' , {
@@ -69,10 +68,7 @@ async function templateAction(
6968 template_id : template ,
7069 } )
7170 } else if ( opts . select ) {
72- const userConfig = getUserConfig ( )
73- if ( userConfig ) {
74- teamId = teamId || userConfig . teamId
75- }
71+ teamId = resolveTeamId ( teamId )
7672
7773 const allTemplates = await listSandboxTemplates ( {
7874 teamID : teamId ,
You can’t perform that action at this time.
0 commit comments