Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

feat(cli): rename team to project in ~/.e2b/config.json (#1570)

Mish Ushakov2defe39bd788
diff --git a/.changeset/minor-config-project.md b/.changeset/minor-config-project.md
new file mode 100644
index 000000000..9f59bee99
--- /dev/null
+++ b/.changeset/minor-config-project.md
@@ -0,0 +1,5 @@
+---
+'@e2b/cli': minor
+---
+
+Rename the `team` fields in `~/.e2b/config.json` to `project`: the config format version is bumped to 2 and `teamName`, `teamId`, and `teamApiKey` become `projectName`, `projectId`, and `projectApiKey`. Existing v1 configs keep working — they are converted to the new format in memory on read, and the file on disk is only rewritten in the new format when the config is persisted anyway (login, `e2b auth configure`, token refresh), so older CLI versions can still read it in the meantime. Unrecognized configs are no longer deleted; the CLI treats them as signed out and `e2b auth login` overwrites them. Tools that read the config file directly must handle the new field names. CLI output and flags are unchanged and still say "team".
diff --git a/packages/cli/src/api.ts b/packages/cli/src/api.ts
index c1d5298d8..600830a5c 100644
--- a/packages/cli/src/api.ts
+++ b/packages/cli/src/api.ts
@@ -44,7 +44,7 @@ export function ensureAPIKey() {
// If apiKey is not already set (either from env var or from user config), try to get it from config file
if (!apiKey) {
const userConfig = getUserConfig()
- apiKey = userConfig?.teamApiKey
+ apiKey = userConfig?.projectApiKey
}
if (!apiKey) {
@@ -83,7 +83,7 @@ export function ensureAccessToken() {
* Resolve project ID with proper precedence:
* 1. CLI --project flag (or the deprecated --team flag)
* 2. E2B_PROJECT_ID env var (or the deprecated E2B_TEAM_ID)
- * 3. ~/.e2b/config.json teamId (only if E2B_API_KEY env var is NOT set,
+ * 3. ~/.e2b/config.json projectId (only if E2B_API_KEY env var is NOT set,
* to avoid mismatch between env var API key and config file project ID)
*/
export function resolveProjectId(cliProjectId?: string): string | undefined {
@@ -91,7 +91,7 @@ export function resolveProjectId(cliProjectId?: string): string | undefined {
if (projectId) return projectId
if (!process.env.E2B_API_KEY) {
const config = getUserConfig()
- return config?.teamId
+ return config?.projectId
}
return undefined
}
@@ -102,7 +102,7 @@ const resolvedAccessToken =
process.env.E2B_ACCESS_TOKEN || userConfig?.tokens.access_token
export const connectionConfig = new e2b.ConnectionConfig({
- apiKey: process.env.E2B_API_KEY || userConfig?.teamApiKey,
+ apiKey: process.env.E2B_API_KEY || userConfig?.projectApiKey,
apiHeaders: resolvedAccessToken
? { Authorization: `Bearer ${resolvedAccessToken}` }
: undefined,
diff --git a/packages/cli/src/commands/auth/configure.ts b/packages/cli/src/commands/auth/configure.ts
index 4ff5f6145..1bbf6ad89 100644
--- a/packages/cli/src/commands/auth/configure.ts
+++ b/packages/cli/src/commands/auth/configure.ts
@@ -1,11 +1,11 @@
import * as commander from 'commander'
-import * as fs from 'fs'
import * as chalk from 'chalk'
import * as e2b from 'e2b'
import {
USER_CONFIG_PATH,
getConfigRefreshTimestamp,
+ getUserConfig,
writeUserConfig,
} from 'src/user'
import { ensureUserConfig, Teams } from 'src/api'
@@ -20,7 +20,9 @@ export const configureCommand = new commander.Command('configure')
console.log('Configuring user...\n')
- if (!fs.existsSync(USER_CONFIG_PATH)) {
+ // A file that exists but fails validation counts as signed out too —
+ // getUserConfig returns null for it (and prints the deprecation message).
+ if (!getUserConfig()) {
console.log('No user config found, run `e2b auth login` to log in first.')
return
}
@@ -46,21 +48,21 @@ export const configureCommand = new commander.Command('configure')
const team = (
await inquirer.default.prompt([
{
- name: 'team',
+ name: 'project',
message: chalk.default.underline('Select project'),
type: 'list',
pageSize: 50,
choices: teams.map((team) => ({
- name: asFormattedTeam(team, userConfig.teamId),
+ name: asFormattedTeam(team, userConfig.projectId),
value: team,
})),
},
])
- )['team']
+ )['project']
- userConfig.teamName = team.name
- userConfig.teamId = team.teamID
- userConfig.teamApiKey = team.apiKey
+ userConfig.projectName = team.name
+ userConfig.projectId = team.teamID
+ userConfig.projectApiKey = team.apiKey
userConfig.last_refresh = getConfigRefreshTimestamp()
writeUserConfig(USER_CONFIG_PATH, userConfig)
diff --git a/packages/cli/src/commands/auth/login.ts b/packages/cli/src/commands/auth/login.ts
index c85a9e146..336ed93f0 100644
--- a/packages/cli/src/commands/auth/login.ts
+++ b/packages/cli/src/commands/auth/login.ts
@@ -65,7 +65,7 @@ export const loginCommand = new commander.Command('login')
}
userConfig = {
- version: 1,
+ version: 2,
identity: {
email: signInResponse.email,
},
@@ -79,9 +79,9 @@ export const loginCommand = new commander.Command('login')
refresh_token: signInResponse.refreshToken,
},
last_refresh: getConfigRefreshTimestamp(),
- teamName: defaultTeam.name,
- teamId: defaultTeam.teamID,
- teamApiKey: defaultTeam.apiKey,
+ projectName: defaultTeam.name,
+ projectId: defaultTeam.teamID,
+ projectApiKey: defaultTeam.apiKey,
}
writeUserConfig(USER_CONFIG_PATH, userConfig)
@@ -90,7 +90,7 @@ export const loginCommand = new commander.Command('login')
console.log(
`Logged in as ${asBold(
userConfig.identity.email
- )} with selected project ${asBold(userConfig.teamName)}`
+ )} with selected project ${asBold(userConfig.projectName)}`
)
process.exit(0)
})
diff --git a/packages/cli/src/user.ts b/packages/cli/src/user.ts
index f3f715129..e8f9ae67f 100644
--- a/packages/cli/src/user.ts
+++ b/packages/cli/src/user.ts
@@ -21,14 +21,14 @@ export interface UserTokens {
}
export interface UserConfig {
- version: 1
+ version: 2
identity: UserIdentity
oauth: UserOAuth
tokens: UserTokens
last_refresh: string
- teamName: string
- teamId: string
- teamApiKey: string
+ projectName: string
+ projectId: string
+ projectApiKey: string
dockerProxySet?: boolean
}
@@ -39,6 +39,9 @@ export const USER_CONFIG_PATH = path.join(os.homedir(), '.e2b', 'config.json') /
export const DEPRECATED_USER_CONFIG_MESSAGE =
'Your CLI authentication config is deprecated. You have been signed out. Please run `e2b auth login` again.'
+// getUserConfig can be called several times per command; warn only once.
+let deprecationWarned = false
+
export const DOCS_BASE =
process.env.E2B_DOCS_BASE ||
`https://${process.env.E2B_DOMAIN || 'e2b.dev'}/docs`
@@ -54,9 +57,20 @@ export function getUserConfig(): UserConfig | null {
if (!fs.existsSync(USER_CONFIG_PATH)) return null
const config = JSON.parse(fs.readFileSync(USER_CONFIG_PATH, 'utf8'))
+ // v1 configs are migrated in memory only — the file on disk is left
+ // untouched so older CLI versions keep working; the v2 format is only
+ // persisted when the config is written anyway (login, configure,
+ // token refresh).
+ const migrated = migrateV1UserConfig(config)
+ if (migrated) return migrated
+
+ // An unrecognized config is treated as being signed out, but the file is
+ // kept on disk — `e2b auth login` overwrites it.
if (!isUserConfig(config)) {
- fs.unlinkSync(USER_CONFIG_PATH)
- console.error(DEPRECATED_USER_CONFIG_MESSAGE)
+ if (!deprecationWarned) {
+ deprecationWarned = true
+ console.error(DEPRECATED_USER_CONFIG_MESSAGE)
+ }
return null
}
@@ -71,9 +85,7 @@ function isString(value: unknown): value is string {
return typeof value === 'string'
}
-function isUserConfig(config: unknown): config is UserConfig {
- if (!isObject(config)) return false
- if (config.version !== 1) return false
+function hasValidAuthFields(config: UnknownRecord): boolean {
return (
isObject(config.identity) &&
isString(config.identity.email) &&
@@ -87,6 +99,43 @@ function isUserConfig(config: unknown): config is UserConfig {
)
}
+function isUserConfig(config: unknown): config is UserConfig {
+ if (!isObject(config)) return false
+ if (config.version !== 2) return false
+ return (
+ hasValidAuthFields(config) &&
+ isString(config.projectName) &&
+ isString(config.projectId) &&
+ isString(config.projectApiKey)
+ )
+}
+
+/**
+ * Convert a v1 config (team* fields) to the v2 format (project* fields).
+ * Returns null if the config is not a valid v1 config.
+ */
+function migrateV1UserConfig(config: unknown): UserConfig | null {
+ if (!isObject(config)) return null
+ if (config.version !== 1) return null
+ if (!hasValidAuthFields(config)) return null
+ if (
+ !isString(config.teamName) ||
+ !isString(config.teamId) ||
+ !isString(config.teamApiKey)
+ ) {
+ return null
+ }
+
+ const { teamName, teamId, teamApiKey, ...rest } = config
+ return {
+ ...rest,
+ version: 2,
+ projectName: teamName,
+ projectId: teamId,
+ projectApiKey: teamApiKey,
+ } as UserConfig
+}
+
export function getConfigRefreshTimestamp(): string {
return new Date().toISOString()
}
diff --git a/packages/cli/src/utils/format.ts b/packages/cli/src/utils/format.ts
index 0a8377fef..900f10a9d 100644
--- a/packages/cli/src/utils/format.ts
+++ b/packages/cli/src/utils/format.ts
@@ -10,11 +10,11 @@ export const primaryColor = '#FFB766'
export function asFormattedConfig(config: UserConfig) {
const email = asBold(config.identity.email)
- const team = config.teamName
- ? asBold(config.teamName)
+ const project = config.projectName
+ ? asBold(config.projectName)
: asRed('Log out and log in to get project name')
- const teamId = asBold(config.teamId)
- return `You are logged in as ${email},\nSelected project: ${team} (${teamId})`
+ const projectId = asBold(config.projectId)
+ return `You are logged in as ${email},\nSelected project: ${project} (${projectId})`
}
export function asFormattedTeam(
diff --git a/packages/cli/tests/commands/sandbox/backend_integration.test.ts b/packages/cli/tests/commands/sandbox/backend_integration.test.ts
index 13ab3084d..4af72a431 100644
--- a/packages/cli/tests/commands/sandbox/backend_integration.test.ts
+++ b/packages/cli/tests/commands/sandbox/backend_integration.test.ts
@@ -20,7 +20,7 @@ const domain =
userConfig?.E2B_DOMAIN ||
userConfig?.domain ||
'e2b.app'
-const apiKey = process.env.E2B_API_KEY || userConfig?.teamApiKey
+const apiKey = process.env.E2B_API_KEY || userConfig?.projectApiKey
const shouldSkip = !apiKey || isDebug
const integrationTest = test.skipIf(shouldSkip)
const templateId =
diff --git a/packages/cli/tests/commands/sandbox/exec_pipe.test.ts b/packages/cli/tests/commands/sandbox/exec_pipe.test.ts
index d5d5bef6b..e57e3ce9e 100644
--- a/packages/cli/tests/commands/sandbox/exec_pipe.test.ts
+++ b/packages/cli/tests/commands/sandbox/exec_pipe.test.ts
@@ -28,7 +28,7 @@ const domain =
userConfig?.E2B_DOMAIN ||
userConfig?.domain ||
'e2b.app'
-const apiKey = process.env.E2B_API_KEY || userConfig?.teamApiKey
+const apiKey = process.env.E2B_API_KEY || userConfig?.projectApiKey
const shouldSkip = !apiKey || isDebug
const integrationTest = test.skipIf(shouldSkip)
const templateId =
diff --git a/packages/cli/tests/user_config_migration.test.ts b/packages/cli/tests/user_config_migration.test.ts
new file mode 100644
index 000000000..a06fd8fb8
--- /dev/null
+++ b/packages/cli/tests/user_config_migration.test.ts
@@ -0,0 +1,105 @@
+import * as fs from 'fs'
+import * as os from 'os'
+import * as path from 'path'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+
+// Point USER_CONFIG_PATH (computed from os.homedir() at module load) at a
+// temp directory. src/user is imported dynamically after mockHome is set.
+let mockHome = ''
+
+vi.mock('os', async (importOriginal: () => Promise<typeof import('os')>) => {
+ const actual = await importOriginal()
+ return {
+ ...actual,
+ homedir: () => mockHome,
+ }
+})
+
+const v1AuthFields = {
+ identity: {
+ email: '[email protected]',
+ },
+ oauth: {
+ token_endpoint: 'https://hydra.example.com/oauth2/token',
+ revoke_endpoint: 'https://hydra.example.com/oauth2/revoke',
+ client_id: 'cli-client-id',
+ },
+ tokens: {
+ access_token: 'access-token-secret',
+ refresh_token: 'refresh-token-secret',
+ },
+ last_refresh: '2024-06-24T12:00:00.000Z',
+}
+
+beforeEach(() => {
+ vi.resetModules()
+ mockHome = fs.mkdtempSync(path.join(os.tmpdir(), 'e2b-config-migration-'))
+})
+
+afterEach(() => {
+ fs.rmSync(mockHome, { recursive: true, force: true })
+ vi.restoreAllMocks()
+})
+
+function writeConfigFile(config: unknown): string {
+ const configPath = path.join(mockHome, '.e2b', 'config.json')
+ fs.mkdirSync(path.dirname(configPath), { recursive: true })
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2))
+ return configPath
+}
+
+describe('getUserConfig', () => {
+ it('migrates a v1 team config to the v2 project format in memory', async () => {
+ writeConfigFile({
+ version: 1,
+ ...v1AuthFields,
+ teamName: 'default',
+ teamId: 'team-id',
+ teamApiKey: 'team-api-key-secret',
+ dockerProxySet: true,
+ })
+
+ const { getUserConfig } = await import('../src/user')
+
+ expect(getUserConfig()).toEqual({
+ version: 2,
+ ...v1AuthFields,
+ projectName: 'default',
+ projectId: 'team-id',
+ projectApiKey: 'team-api-key-secret',
+ dockerProxySet: true,
+ })
+ })
+
+ it('returns a valid v2 config as-is', async () => {
+ const v2Config = {
+ version: 2,
+ ...v1AuthFields,
+ projectName: 'default',
+ projectId: 'project-id',
+ projectApiKey: 'project-api-key-secret',
+ }
+ writeConfigFile(v2Config)
+
+ const { getUserConfig } = await import('../src/user')
+ expect(getUserConfig()).toEqual(v2Config)
+ })
+
+ it('treats an unrecognized config as signed out without deleting it', async () => {
+ const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {
+ /* silence deprecation message */
+ })
+ const configPath = writeConfigFile({
+ version: 1,
+ ...v1AuthFields,
+ // Missing team* fields — cannot be migrated.
+ })
+
+ const { getUserConfig, DEPRECATED_USER_CONFIG_MESSAGE } = await import(
+ '../src/user'
+ )
+ expect(getUserConfig()).toBeNull()
+ expect(fs.existsSync(configPath)).toBe(true)
+ expect(consoleError).toHaveBeenCalledWith(DEPRECATED_USER_CONFIG_MESSAGE)
+ })
+})
diff --git a/packages/cli/tests/user_config_permissions.test.ts b/packages/cli/tests/user_config_permissions.test.ts
index 08b616f9b..639fbdd53 100644
--- a/packages/cli/tests/user_config_permissions.test.ts
+++ b/packages/cli/tests/user_config_permissions.test.ts
@@ -19,7 +19,7 @@ describe('writeUserConfig', () => {
tmpDirs.push(tmpDir)
const configPath = path.join(tmpDir, '.e2b', 'config.json')
const config: UserConfig = {
- version: 1,
+ version: 2,
identity: {
},
@@ -33,9 +33,9 @@ describe('writeUserConfig', () => {
refresh_token: 'refresh-token-secret',
},
last_refresh: '2024-06-24T12:00:00.000Z',
- teamName: 'default',
- teamId: 'team-id',
- teamApiKey: 'team-api-key-secret',
+ projectName: 'default',
+ projectId: 'project-id',
+ projectApiKey: 'project-api-key-secret',
}
writeUserConfig(configPath, config)