Skip to content

Add --user/--cwd/--env terminal flags to sandbox create & connect#1501

Open
mishushakov wants to merge 1 commit into
mainfrom
mishushakov/move-parseenv-to-shared-utils
Open

Add --user/--cwd/--env terminal flags to sandbox create & connect#1501
mishushakov wants to merge 1 commit into
mainfrom
mishushakov/move-parseenv-to-shared-utils

Conversation

@mishushakov

Copy link
Copy Markdown
Member

Exposes --user, --cwd, and repeatable --env KEY=VALUE flags on e2b sandbox create (and the deprecated spawn alias) and e2b sandbox connect, forwarding them to the underlying PTY session so the connected terminal starts as the given user, in the given working directory, and with the given environment variables. The SDKs already supported these PTY options — this just wires them through the CLI. The --env arg parser is extracted into a shared src/utils/env.ts and reused across create, connect, and exec. Added unit tests for the parser and CLI tests covering the new flags; a changeset is included for @e2b/cli.

Usage

# Start the terminal as root, in /app, with custom env vars
e2b sandbox create base --user root --cwd /app --env FOO=bar --env TOKEN=abc123

# Same flags when attaching to an already-running sandbox
e2b sandbox connect <sandboxID> --user root --cwd /app --env FOO=bar

🤖 Generated with Claude Code

Expose --user, --cwd, and repeatable --env KEY=VALUE flags on
`e2b sandbox create` (and the deprecated `spawn` alias) and
`e2b sandbox connect`, forwarding them to the underlying PTY session.
Extract the shared --env arg parser into src/utils/env.ts and reuse it
across create, connect, and exec.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@cursor

cursor Bot commented Jun 29, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
CLI-only flag plumbing to existing PTY APIs; behavior is covered partly by tests but connect is untested.

Overview
e2b sandbox create, deprecated spawn, and e2b sandbox connect gain --user, --cwd, and repeatable --env KEY=VALUE; values flow through TerminalOpts into sandbox.pty.create. Repeatable --env parsing is centralized in parseEnv and sandbox exec uses it instead of an inline parser.

There are no automated tests for connect forwarding these flags (coverage is only on create and parseEnv).

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

@changeset-bot

changeset-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cab456f

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

@github-actions

Copy link
Copy Markdown
Contributor

Package Artifacts

Built from 77ccf17. Download artifacts from this workflow run.

JS SDK (e2b@2.31.1-mishushakov-move-parseenv-to-shared-utils.0):

npm install ./e2b-2.31.1-mishushakov-move-parseenv-to-shared-utils.0.tgz

CLI (@e2b/cli@2.13.1-mishushakov-move-parseenv-to-shared-utils.0):

npm install ./e2b-cli-2.13.1-mishushakov-move-parseenv-to-shared-utils.0.tgz

Python SDK (e2b==2.30.0+mishushakov-move-parseenv-to-shared-utils):

pip install ./e2b-2.30.0+mishushakov.move.parseenv.to.shared.utils-py3-none-any.whl

@claude claude 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.

LGTM — straightforward CLI flag plumbing through to existing SDK PTY options, with tests and a changeset.

Extended reasoning...

Overview

This PR adds three new flags (--user, --cwd, repeatable --env KEY=VALUE) to the e2b sandbox create and e2b sandbox connect CLI commands and forwards them to the underlying PTY session via the existing SDK options. It also extracts the existing --env parser from exec.ts into a shared src/utils/env.ts and reuses it across the three commands. Includes unit tests for the parser, CLI tests for the new flags, and a changeset.

Security risks

None apparent. The flag values are passed as parameters through to the SDK's pty.create call which the SDKs already support — no new shell-escaping or process-exec surface is introduced in the CLI layer. The parseEnv helper only splits on = and assigns to a plain object; behavior is equivalent to the prior in-line version it replaces.

Level of scrutiny

Low. This is CLI-only code (no auth, crypto, or server-side logic), the change is small (~150 lines including tests), follows the existing pattern used in exec.ts, and is well-tested. The TerminalOpts conditional spread also correctly avoids passing undefined keys to the SDK.

Other factors

The bug hunting system found no issues. New tests cover the happy path (flags forwarded correctly), the edge case of = inside values, and the no-env-flags case. The shared parseEnv extraction is a behavior-preserving refactor of code that already existed in exec.ts.

@mishushakov mishushakov requested review from Kraci and huv1k June 29, 2026 13:36
@mishushakov mishushakov enabled auto-merge (squash) June 30, 2026 13:15
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