Skip to content

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

Merged
mishushakov merged 2 commits intomainfrom
mishushakov/sandbox-template-option
Apr 17, 2026
Merged

feat: allow passing template as option in Sandbox.create()#1267
mishushakov merged 2 commits intomainfrom
mishushakov/sandbox-template-option

Conversation

@mishushakov
Copy link
Copy Markdown
Member

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

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cursor
Copy link
Copy Markdown

cursor bot commented Apr 13, 2026

PR Summary

Low Risk
Low risk, localized SDK API enhancement that preserves existing Sandbox.create('<template>') behavior while only changing template selection precedence when opts.template is provided.

Overview
Sandbox.create() and Sandbox.betaCreate() in the JS SDK now accept a template via the options object (e.g. Sandbox.create({ template: 'my-template' })), and will prefer opts.template before falling back to the default or MCP template.

Updates SandboxOpts to include an optional template field (with docs) and adds a patch changeset to release this behavior change.

Reviewed by Cursor Bugbot for commit 521d043. Bugbot is set up for automated code reviews on this repo. Configure here.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 13, 2026

🦋 Changeset detected

Latest commit: 521d043

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
e2b Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mishushakov mishushakov enabled auto-merge (squash) April 13, 2026 15:12
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

Package Artifacts

Built from c14bbd0. Download artifacts from this workflow run.

JS SDK (e2b@2.19.1-mishushakov-sandbox-template-option.0):

npm install ./e2b-2.19.1-mishushakov-sandbox-template-option.0.tgz

CLI (@e2b/cli@2.9.1-mishushakov-sandbox-template-option.0):

npm install ./e2b-cli-2.9.1-mishushakov-sandbox-template-option.0.tgz

Python SDK (e2b==2.20.0+mishushakov-sandbox-template-option):

pip install ./e2b-2.20.0+mishushakov.sandbox.template.option-py3-none-any.whl

Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — small, backwards-compatible feature addition with correct logic.

Extended reasoning...

Overview

The PR adds a template optional field to SandboxOpts and threads it through create/betaCreate with a simple nullish-coalescing expression before the existing MCP/default fallback. Changeset is included. Three files changed: the interface definition, the two overloaded create methods, and the changeset.

Security risks

None. This is a pure convenience API addition — no auth, crypto, or permissions code is touched. The template string is already passed through to the API in the same way as the positional-string overload.

Level of scrutiny

Low. The logic change is minimal and mechanical: templateOrOpts?.template ?? (existing expression). Both call sites are updated identically. Backwards compatibility is preserved for the string-argument and no-argument forms.

Other factors

The only finding is a JSDoc nit (@default 'base' being inaccurate when mcp is also set), which is documentation-only and does not affect runtime behavior. No outstanding reviewer comments or unresolved threads exist. The inline comment already captures this nit for the author.

Comment thread packages/js-sdk/src/sandbox/sandboxApi.ts
Copy link
Copy Markdown
Member

@jakubno jakubno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe worth mentioning that if you specify mcp, it won't have any effect

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mishushakov mishushakov merged commit 4065ecd into main Apr 17, 2026
73 of 83 checks passed
@mishushakov mishushakov deleted the mishushakov/sandbox-template-option branch April 17, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants