feat: enable piping on the e2b cli#1127
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 86d629264d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
| const userConfig = safeGetUserConfig() as UserConfigWithDomain | null | ||
| const domain = | ||
| process.env.E2B_DOMAIN || | ||
| userConfig?.E2B_DOMAIN || | ||
| userConfig?.domain || | ||
| 'e2b.app' | ||
| const apiKey = process.env.E2B_API_KEY || userConfig?.teamApiKey | ||
| const templateId = | ||
| process.env.E2B_PIPE_TEMPLATE_ID || | ||
| process.env.E2B_TEMPLATE_ID || | ||
| 'base' | ||
| const isDebug = process.env.E2B_DEBUG !== undefined | ||
| const hasCreds = Boolean(apiKey) | ||
| const shouldSkip = !hasCreds || isDebug | ||
| const testIf = test.skipIf(shouldSkip) | ||
| const includeLargeBinary = | ||
| process.env.E2B_PIPE_INTEGRATION_STRICT === '1' || | ||
| process.env.E2B_PIPE_INTEGRATION_BINARY === '1' || | ||
| process.env.E2B_PIPE_SMOKE_STRICT === '1' || // Backward compatibility. | ||
| process.env.E2B_PIPE_SMOKE_BINARY === '1' || // Backward compatibility. | ||
| process.env.STRICT === '1' | ||
| const sandboxTimeoutMs = parseEnvInt('E2B_PIPE_SANDBOX_TIMEOUT_MS', 10_000) | ||
| const testTimeoutMs = parseEnvInt('E2B_PIPE_TEST_TIMEOUT_MS', 60_000) | ||
| const defaultCmdTimeoutMs = parseEnvInt( | ||
| 'E2B_PIPE_CMD_TIMEOUT_MS', | ||
| Math.min(8_000, testTimeoutMs) | ||
| ) |
| } | ||
| } | ||
|
|
||
| async function killProcessBestEffort( |
There was a problem hiding this comment.
this is unnecessary function
| } | ||
| type FsLike = { fstatSync: (fd: number) => StatLike } | ||
|
|
||
| export const isPipedStdin = (fd = 0, fsModule: FsLike = fs as FsLike) => { |
There was a problem hiding this comment.
not a fan of passing around modules here (fs)
| function sandboxExistsInList( | ||
| output: string | Buffer | null | undefined, | ||
| sandboxId: string | ||
| ): boolean { | ||
| const text = bufferToText(output).trim() | ||
| if (!text) { | ||
| return false | ||
| } | ||
|
|
||
| const parsed = JSON.parse(text) as Array<{ sandboxId?: string }> | ||
| return parsed.some((item) => item.sandboxId === sandboxId) | ||
| } | ||
|
|
||
| function bufferToText(value: Buffer | string | null | undefined): string { | ||
| if (!value) { | ||
| return '' | ||
| } | ||
| return typeof value === 'string' ? value : value.toString('utf8') | ||
| } | ||
|
|
||
| function parseEnvInt(name: string, fallback: number): number { | ||
| const raw = process.env[name] | ||
| if (!raw) { | ||
| return fallback | ||
| } | ||
| const parsed = Number.parseInt(raw, 10) | ||
| return Number.isFinite(parsed) ? parsed : fallback | ||
| } | ||
|
|
||
| function safeGetUserConfig(): ReturnType<typeof getUserConfig> | null { | ||
| try { | ||
| return getUserConfig() | ||
| } catch (err) { | ||
| console.warn(`Failed to read ~/.e2b/config.json: ${String(err)}`) | ||
| return null | ||
| } | ||
| } |
There was a problem hiding this comment.
I'd avoid small helper functions unless you plan to re-use them anywhere else
|
please lower the vibes a little bit on the tests. it's fine we just do integration tests on the CLI, no need for mock/units here. |
Adds stdin piping support to
e2b sandbox exec, so users can do:Included:
envd>= 0.5.2, warn + ignore piped input)Example Usage
non-piped exec still works
piped stdin path (supported envd) should deliver bytes
optional: legacy template behavior should warn + ignore piped stdin