Skip to content

Commit 4065ecd

Browse files
mishushakovclaude
andauthored
feat: allow passing template as option in Sandbox.create() (#1267)
## Summary - Adds `template` as an optional property on `SandboxOpts` in the JS SDK, enabling `Sandbox.create({ template: 'my-template' })` syntax - Updates both `create` and `betaCreate` to check `opts.template` before falling back to the default template - Python SDK already supports `Sandbox.create(template='template')` via named parameters, so no changes needed there ## Test plan - [ ] Verify `Sandbox.create({ template: 'base' })` works - [ ] Verify `Sandbox.create('base')` still works (backwards compatible) - [ ] Verify `Sandbox.create()` still defaults to `'base'` - [ ] Verify MCP template fallback still works when no template is specified 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f667f33 commit 4065ecd

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

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()

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,11 @@ export class Sandbox extends SandboxApi {
273273
sandboxOpts: opts,
274274
}
275275
: {
276-
template: templateOrOpts?.mcp
277-
? this.defaultMcpTemplate
278-
: this.defaultTemplate,
276+
template:
277+
templateOrOpts?.template ??
278+
(templateOrOpts?.mcp
279+
? this.defaultMcpTemplate
280+
: this.defaultTemplate),
279281
sandboxOpts: templateOrOpts,
280282
}
281283

@@ -368,9 +370,11 @@ export class Sandbox extends SandboxApi {
368370
sandboxOpts: opts,
369371
}
370372
: {
371-
template: templateOrOpts?.mcp
372-
? this.defaultMcpTemplate
373-
: this.defaultTemplate,
373+
template:
374+
templateOrOpts?.template ??
375+
(templateOrOpts?.mcp
376+
? this.defaultMcpTemplate
377+
: this.defaultTemplate),
374378
sandboxOpts: templateOrOpts,
375379
}
376380

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)