Skip to main content
You can execute commands in a running sandbox.
e2b sandbox exec <sandbox-id> <command>

Run in background

Use the --background flag to run a command in the background and return immediately. The command will print the process ID (PID) to stderr:
e2b sandbox exec --background <sandbox-id> "sleep 60 && echo done"

Set working directory

Use the --cwd flag to specify the working directory for the command:
e2b sandbox exec --cwd /home/user <sandbox-id> ls

Run as specific user

Use the --user flag to run the command as a specific user:
e2b sandbox exec --user root <sandbox-id> apt-get update

Set environment variables

Use the --env flag to set environment variables. This flag can be repeated for multiple variables:
e2b sandbox exec --env NODE_ENV=production --env DEBUG=true <sandbox-id> node app.js