Skip to content

v2 SDK Template.build(): runCmd() filesystem changes not persisted in sandbox #1238

@link2004

Description

@link2004

Description

When building a custom template using the v2 TypeScript SDK Template.build(), all runCmd() filesystem changes are lost when a sandbox is created from the resulting template. The sandbox always boots from the clean base image.

Reproduction

import { Template, waitForPort } from 'e2b'

const template = Template()
  .fromNodeImage('20')
  .skipCache()
  .setUser('root')
  .runCmd('npm install -g cowsay')  // or any global package
  .runCmd('cowsay "test" > /tmp/marker.txt')
  .setUser('user')
  .setStartCmd('echo ready', 'sleep 1')

const result = await Template.build(template, 'test-persistence', {
  skipCache: true,
  onBuildLogs: defaultBuildLogger(),
})
// Build succeeds, logs show "Template is ready"

const sbx = await Sandbox.create({ template: result.templateId })
await sbx.commands.run('cowsay "hello"')  // ❌ command not found
await sbx.commands.run('cat /tmp/marker.txt')  // ❌ file not found

Build log (shows success)

[builder 3/7] RUN npm install -g cowsay  ← succeeds
[builder 7/7] RUN cowsay "test" > /tmp/marker.txt  ← succeeds
[finalize] Finalizing template build
Running start command: echo ready
Template is ready
Build finished, took 1m13s

At runtime (sandbox from template)

  • /usr/local/lib/node_modules/ only contains base image packages (corepack, npm, yarn)
  • /tmp/marker.txt does not exist
  • NODE_PATH and other setEnvs() values are not set
  • /home/user/ is in initial state

What I tried

Approach Result
fromImage('node:20-slim') Changes not persisted
fromNodeImage('20') Changes not persisted
setUser('root') + runCmd('npm install -g ...') Changes not persisted
.npmInstall('pkg', { g: true }) Changes not persisted
.skipCache() chained on template Changes not persisted
skipCache: true in build options Changes not persisted
.setStartCmd() with ready check Build says "Template is ready", still not persisted
Install to /opt/ instead of /home/user/ Changes not persisted
Fresh template name (unique ID each time) Changes not persisted

Environment

  • SDK: e2b@2.18.0
  • CLI: @e2b/cli@2.9.0
  • Plan: Hobby
  • Node.js: v24.3.0 (local), v20.9.0 (sandbox)

Expected behavior

Filesystem changes made by runCmd() during Template.build() should be present in sandboxes created from that template.

Actual behavior

Sandbox always boots from the clean base image. All runCmd() changes, setEnvs() values, and installed packages are absent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions