diff --git a/.changeset/sandbox-template-option.md b/.changeset/sandbox-template-option.md new file mode 100644 index 0000000000..56162ef525 --- /dev/null +++ b/.changeset/sandbox-template-option.md @@ -0,0 +1,5 @@ +--- +'e2b': patch +--- + +allow passing template as an option in Sandbox.create() diff --git a/packages/js-sdk/src/sandbox/index.ts b/packages/js-sdk/src/sandbox/index.ts index 7384dc7af2..cfa51504f7 100644 --- a/packages/js-sdk/src/sandbox/index.ts +++ b/packages/js-sdk/src/sandbox/index.ts @@ -273,9 +273,11 @@ export class Sandbox extends SandboxApi { sandboxOpts: opts, } : { - template: templateOrOpts?.mcp - ? this.defaultMcpTemplate - : this.defaultTemplate, + template: + templateOrOpts?.template ?? + (templateOrOpts?.mcp + ? this.defaultMcpTemplate + : this.defaultTemplate), sandboxOpts: templateOrOpts, } @@ -368,9 +370,11 @@ export class Sandbox extends SandboxApi { sandboxOpts: opts, } : { - template: templateOrOpts?.mcp - ? this.defaultMcpTemplate - : this.defaultTemplate, + template: + templateOrOpts?.template ?? + (templateOrOpts?.mcp + ? this.defaultMcpTemplate + : this.defaultTemplate), sandboxOpts: templateOrOpts, } diff --git a/packages/js-sdk/src/sandbox/sandboxApi.ts b/packages/js-sdk/src/sandbox/sandboxApi.ts index f1bcf86bf2..6fc03addb7 100644 --- a/packages/js-sdk/src/sandbox/sandboxApi.ts +++ b/packages/js-sdk/src/sandbox/sandboxApi.ts @@ -107,6 +107,13 @@ export interface SandboxApiOpts * Options for creating a new Sandbox. */ export interface SandboxOpts extends ConnectionOpts { + /** + * Sandbox template name or ID. + * + * @default 'base' (or 'mcp-gateway' when `mcp` option is set) + */ + template?: string + /** * Custom metadata for the sandbox. *