Skip to main content
The default user in the template is user with the /home/user (home directory) as the working directory. This is different from the Docker defaults, where the default user is root with / as the working directory. This is to help with tools installation, and to improve default security. The last set user and workdir in the template is then persisted as a default to the sandbox execution. Example of setting user and workdir in the template definition are below.
Requires the E2B SDK version at least 2.3.0
const template = Template()
  .fromBaseImage()
  .runCmd("whoami") // user
  .runCmd("pwd") // /home/user
  .setUser("guest")
  .runCmd("whoami") // guest
  .runCmd("pwd") // /home/guest

const sbx = await Sandbox.create()
await sbx.commands.run("whoami") // guest
await sbx.commands.run("pwd") // /home/guest
const template = Template()
  .fromBaseImage()
  .runCmd("whoami") // user
  .runCmd("pwd") // /home/user

const sbx = await Sandbox.create()
await sbx.commands.run("whoami") // user
await sbx.commands.run("pwd") // /home/user
I