Skip to content

Commit fe8b38b

Browse files
authored
Merge branch 'main' into fix/1249-snapshot-name-param
2 parents ba584c1 + a6a1156 commit fe8b38b

18 files changed

Lines changed: 69 additions & 27 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"e2b": patch
3+
"@e2b/python-sdk": patch
4+
---
5+
6+
fix(sdk): prevent shell injection in MCP config by using proper shell escaping (shlex.quote in Python, shellQuote helper in JS/TS)

.changeset/icy-eggs-change.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@e2b/cli': minor
3+
---
4+
5+
Handle sandbox not found on cli info
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'e2b': patch
3+
---
4+
5+
allow passing template as an option in Sandbox.create()

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Use pnpm for node and poetry for python to install and update dependencies.
2-
Run `pnpm run format`, `pnpm run lint` and `pnpm run typecheck` before commiting changes.
2+
Run `pnpm run format`, `pnpm run lint` and `pnpm run typecheck` before committing changes.
33
To re-generate the API client run `make codegen` in the repository root.
44
Run tests on affected codepaths using `pnpm run test`.
55
Default credentials are stored in .env.local in the repository root or inside ~/.e2b/config.json.

packages/cli/src/commands/sandbox/info.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as commander from 'commander'
2-
import { Sandbox } from 'e2b'
2+
import { NotFoundError, Sandbox } from 'e2b'
33

44
import { ensureAPIKey } from 'src/api'
55
import { asBold } from 'src/utils/format'
@@ -62,6 +62,11 @@ export const infoCommand = new commander.Command('info')
6262
process.exit(1)
6363
}
6464
} catch (err: any) {
65+
if (err instanceof NotFoundError) {
66+
console.error(`Sandbox ${asBold(sandboxID)} wasn't found`)
67+
process.exit(1)
68+
return
69+
}
6570
console.error(err)
6671
process.exit(1)
6772
}

packages/cli/src/utils/confirm.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
export async function confirm(text: string, defaultAnwser = false) {
1+
export async function confirm(text: string, defaultAnswer = false) {
22
const inquirer = await import('inquirer')
33
const confirmAnswers = await inquirer.default.prompt([
44
{
55
name: 'confirm',
66
type: 'confirm',
7-
default: defaultAnwser,
7+
default: defaultAnswer,
88
message: text,
99
},
1010
])

packages/cli/src/utils/templatePrompt.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export async function getPromptTemplates(
88
text: string
99
) {
1010
const inquirer = await import('inquirer')
11-
const templatesAnwsers = await inquirer.default.prompt([
11+
const templatesAnswers = await inquirer.default.prompt([
1212
{
1313
name: 'templates',
1414
message: chalk.default.underline(text),
@@ -21,7 +21,7 @@ export async function getPromptTemplates(
2121
},
2222
])
2323

24-
return templatesAnwsers[
24+
return templatesAnswers[
2525
'templates'
2626
] as e2b.components['schemas']['Template'][]
2727
}

packages/js-sdk/src/sandbox/git/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ export class Git {
937937
/**
938938
* Execute a raw shell command while applying default git environment variables.
939939
*
940-
Note: We can liekly just modify runGit later to allow appending commands to the git but for now it's separate.
940+
Note: We can likely just modify runGit later to allow appending commands to the git but for now it's separate.
941941
*/
942942
private async runShell(
943943
cmd: string,

packages/js-sdk/src/sandbox/index.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { getSignature } from './signature'
2929
import { compareVersions } from 'compare-versions'
3030
import { SandboxError } from '../errors'
3131
import { ENVD_DEBUG_FALLBACK, ENVD_DEFAULT_USER } from '../envd/versions'
32+
import { shellQuote } from '../utils'
3233

3334
/**
3435
* Options for sandbox upload/download URL generation.
@@ -273,9 +274,11 @@ export class Sandbox extends SandboxApi {
273274
sandboxOpts: opts,
274275
}
275276
: {
276-
template: templateOrOpts?.mcp
277-
? this.defaultMcpTemplate
278-
: this.defaultTemplate,
277+
template:
278+
templateOrOpts?.template ??
279+
(templateOrOpts?.mcp
280+
? this.defaultMcpTemplate
281+
: this.defaultTemplate),
279282
sandboxOpts: templateOrOpts,
280283
}
281284

@@ -299,7 +302,7 @@ export class Sandbox extends SandboxApi {
299302
if (sandboxOpts?.mcp) {
300303
sandbox.mcpToken = crypto.randomUUID()
301304
const res = await sandbox.commands.run(
302-
`mcp-gateway --config '${JSON.stringify(sandboxOpts?.mcp)}'`,
305+
`mcp-gateway --config ${shellQuote(JSON.stringify(sandboxOpts.mcp))}`,
303306
{
304307
user: 'root',
305308
envs: {
@@ -368,9 +371,11 @@ export class Sandbox extends SandboxApi {
368371
sandboxOpts: opts,
369372
}
370373
: {
371-
template: templateOrOpts?.mcp
372-
? this.defaultMcpTemplate
373-
: this.defaultTemplate,
374+
template:
375+
templateOrOpts?.template ??
376+
(templateOrOpts?.mcp
377+
? this.defaultMcpTemplate
378+
: this.defaultTemplate),
374379
sandboxOpts: templateOrOpts,
375380
}
376381

@@ -394,7 +399,7 @@ export class Sandbox extends SandboxApi {
394399
if (sandboxOpts?.mcp) {
395400
sandbox.mcpToken = crypto.randomUUID()
396401
const res = await sandbox.commands.run(
397-
`mcp-gateway --config '${JSON.stringify(sandboxOpts?.mcp)}'`,
402+
`mcp-gateway --config ${shellQuote(JSON.stringify(sandboxOpts.mcp))}`,
398403
{
399404
user: 'root',
400405
envs: {

packages/js-sdk/src/sandbox/sandboxApi.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ export interface SandboxApiOpts
107107
* Options for creating a new Sandbox.
108108
*/
109109
export interface SandboxOpts extends ConnectionOpts {
110+
/**
111+
* Sandbox template name or ID.
112+
*
113+
* @default 'base' (or 'mcp-gateway' when `mcp` option is set)
114+
*/
115+
template?: string
116+
110117
/**
111118
* Custom metadata for the sandbox.
112119
*

0 commit comments

Comments
 (0)