Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

feat: allow passing template as option in Sandbox.create() (#1267)

Mish Ushakov4065ecd68c40
diff --git a/.changeset/sandbox-template-option.md b/.changeset/sandbox-template-option.md
new file mode 100644
index 000000000..56162ef52
--- /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 7384dc7af..cfa51504f 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 f1bcf86bf..6fc03addb 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.
*