Use this file to discover all available pages before exploring further.
Templates define a sandbox’s base environment, but many workloads need dynamic configuration — different packages per user, files uploaded at request time, or settings that change between runs. This page covers patterns for customizing sandboxes after creation.
For packages you install in every sandbox, add them to a template instead. Template-based installs are faster because they’re baked into the sandbox image.
If multiple sandboxes need the same runtime setup, install once and snapshot the result. New sandboxes start from the snapshot with everything already installed.
import { Sandbox } from 'e2b'// First time: install and snapshotconst sandbox = await Sandbox.create()await sandbox.commands.run('pip install pandas numpy scikit-learn')const snapshot = await sandbox.createSnapshot()console.log('Snapshot ID:', snapshot.snapshotId)// Later: start from snapshot — packages are already installedconst fast = await Sandbox.create(snapshot.snapshotId)
Use sandbox.files.write() to upload configuration files, scripts, or user data into the sandbox. See the Filesystem page for the full file operations API.
import { Sandbox } from 'e2b'const sandbox = await Sandbox.create()// Upload a configuration fileawait sandbox.files.write('/home/user/config.json', JSON.stringify({ apiEndpoint: 'https://api.example.com', maxRetries: 3,}))// Upload a scriptawait sandbox.files.write('/home/user/analyze.py', `import jsonwith open('config.json') as f: config = json.load(f)print(f"Connecting to {config['apiEndpoint']}")`)// Run the uploaded scriptconst result = await sandbox.commands.run('cd /home/user && python analyze.py')console.log(result.stdout)