Skip to content

feat(cli): accept E2B_API_KEY in template list & create#1361

Open
mishushakov wants to merge 9 commits into
mainfrom
mishushakov/cli-access-token-methods
Open

feat(cli): accept E2B_API_KEY in template list & create#1361
mishushakov wants to merge 9 commits into
mainfrom
mishushakov/cli-access-token-methods

Conversation

@mishushakov

@mishushakov mishushakov commented May 28, 2026

Copy link
Copy Markdown
Member

Summary

E2B_ACCESS_TOKEN is deprecated, so CLI commands whose endpoints accept either credential now authenticate with E2B_API_KEY instead of requiring an access token.

  • e2b template list now uses ensureAPIKey(). The underlying GET /templates endpoint accepts both ApiKeyAuth and AccessTokenAuth, and since the access token is deprecated we standardize on the API key.
  • e2b template create no longer calls ensureAccessToken(). Its only API calls — POST /v3/templates and POST /v2/templates/{id}/builds/{bid} (via the SDK's Template.build) — accept only ApiKeyAuth, so requiring an access token locked out API-key-only environments for no reason.
  • e2b template build is intentionally left as-is: its v1 endpoints and docker-registry login are access-token-only at the API level.
  • Removed the now-unused ensureAccessTokenOrAPIKey() helper and the 'BOTH' variant of the auth-error box that an earlier iteration of this PR introduced.
  • Adds a real backend-integration test in tests/commands/template/create.test.ts that mirrors the existing backend_integration.test.ts pattern: use the real E2B_DOMAIN and assert end-to-end that template create succeeds with only E2B_API_KEY set (no E2B_ACCESS_TOKEN). Uses a unique template name per run and cleans up the created template in afterAll.

Test plan

  • pnpm --filter @e2b/cli run typecheck
  • pnpm --filter @e2b/cli run lint
  • pnpm --filter @e2b/cli run format
  • pnpm --filter @e2b/cli run test (local, with real E2B_API_KEY — new test passes; create succeeds without E2B_ACCESS_TOKEN)

🤖 Generated with Claude Code

The GET /templates endpoint supports both AccessTokenAuth and ApiKeyAuth,
so the CLI no longer forces an access token when only an API key is
available. Adds ensureAccessTokenOrAPIKey() helper and updates the
auth error box to mention both credentials when either is acceptable.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented May 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ab24582

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@e2b/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cursor

cursor Bot commented May 28, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
CLI-only credential selection aligned with API-key-capable endpoints; no server or security-policy changes.

Overview
e2b template list and e2b template create now require E2B_API_KEY (via ensureAPIKey) instead of E2B_ACCESS_TOKEN, so API-key-only setups such as CI/CD can list and create templates without a personal access token. template create drops the upfront ensureAccessToken() call; listing swaps ensureAccessToken() for ensureAPIKey().

Shared authErrorBox in api.ts is tightened to a typed 'E2B_API_KEY' | 'E2B_ACCESS_TOKEN' helper with the same user-facing messaging. A changeset documents the behavior change, and a new backend integration test runs template create with only E2B_API_KEY in the child process env and asserts a successful build.

Reviewed by Cursor Bugbot for commit ab24582. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

github-actions Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Package Artifacts

Built from efb2f73. Download artifacts from this workflow run.

JS SDK (e2b@2.27.2-mishushakov-cli-access-token-methods.0):

npm install ./e2b-2.27.2-mishushakov-cli-access-token-methods.0.tgz

CLI (@e2b/cli@2.10.3-mishushakov-cli-access-token-methods.0):

npm install ./e2b-cli-2.10.3-mishushakov-cli-access-token-methods.0.tgz

Python SDK (e2b==2.25.1+mishushakov-cli-access-token-methods):

pip install ./e2b-2.25.1+mishushakov.cli.access.token.methods-py3-none-any.whl

template create only calls API-key-authenticated endpoints (POST
/v3/templates and POST /v2/templates/{id}/builds/{bid} via the SDK
Template.build), so requiring E2B_ACCESS_TOKEN locked out API-key-only
environments for no reason.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@mishushakov mishushakov changed the title feat(cli): accept E2B_API_KEY in e2b template list feat(cli): accept E2B_API_KEY in template list & create May 28, 2026
mishushakov and others added 6 commits May 28, 2026 15:45
Adds four tests that lock in the API-key-only auth behavior:
- template create succeeds past credential checks with only E2B_API_KEY
- without any credentials, the error advertises E2B_API_KEY (not
  E2B_ACCESS_TOKEN), since the underlying endpoints are API-key only
- invalid template names fail before any credential check
- odd memory values are rejected

Tests run the CLI subprocess with an isolated HOME so the user's
~/.e2b/config.json cannot leak credentials in.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Drop the no-credentials, invalid-name, and odd-memory tests — those
cover pre-existing CLI behavior unrelated to this PR. Keep only the
positive scenario: with E2B_API_KEY set and no E2B_ACCESS_TOKEN, the
command reaches "Building sandbox template..." without printing the
access-token auth-error box.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Mirror the backend_integration.test.ts pattern: skip when no API key is
available, use the real E2B_DOMAIN, and assert a real end-to-end
template create succeeds with only E2B_API_KEY set (no
E2B_ACCESS_TOKEN). Uses a unique template name per run and cleans up
the created template in afterAll. Base image is ubuntu:latest since
alpine is not a supported E2B base.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Drop the UserConfigWithDomain fallback chain, safeGetUserConfig,
parseEnvInt, and bufferToText helpers. CI sets E2B_API_KEY and
E2B_DOMAIN directly, so the user-config fallback and configurable
timeout aren't needed. Inline String() coercion replaces bufferToText.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Skipping silently when E2B_API_KEY is missing meant CI runs with broken
credential setup would pass green. Now beforeAll throws a clear message
so missing creds surface as a real failure.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
E2B_ACCESS_TOKEN is deprecated, so commands whose endpoints accept
either credential now authenticate with E2B_API_KEY instead of
introducing an accept-either path. Drops the ensureAccessTokenOrAPIKey
helper and the 'BOTH' auth-error-box variant.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ab24582. Configure here.

Comment thread packages/cli/src/commands/template/list.ts
Comment thread packages/cli/tests/commands/template/create.test.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant