commands.run() method.
Custom shell
By default, commands run in a Bash login shell (/bin/bash -l -c <cmd>). Pass the shell option to run the command with a different executable and arguments; the command is appended as the last argument.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Run terminal commands in an E2B sandbox with commands.run(), and pass a custom shell instead of the default Bash login shell.
commands.run() method.
import { Sandbox } from 'e2b'
const sandbox = await Sandbox.create()
const result = await sandbox.commands.run('ls -l')
console.log(result)
from e2b import Sandbox
sandbox = Sandbox.create()
result = sandbox.commands.run('ls -l')
print(result)
/bin/bash -l -c <cmd>). Pass the shell option to run the command with a different executable and arguments; the command is appended as the last argument.
import { Sandbox } from 'e2b'
const sandbox = await Sandbox.create()
const result = await sandbox.commands.run('print(6 * 7)', {
shell: ['python3', '-c'], // Runs `python3 -c 'print(6 * 7)'`
})
console.log(result.stdout) // 42
from e2b import Sandbox
sandbox = Sandbox.create()
result = sandbox.commands.run('print(6 * 7)', shell=['python3', '-c']) # Runs `python3 -c 'print(6 * 7)'`
print(result.stdout) # 42
Was this page helpful?