Use this file to discover all available pages before exploring further.
Each E2B Sandbox has its own isolated filesystem. The Hobby tier sandboxes come with 10 GB of the free disk space and Pro tier sandboxes come with 20 GB.With E2B SDK you can read and write files, get file and directory metadata, watch directories for changes, upload data to the sandbox, and download data from the sandbox.
You can get information about a file or directory using the files.getInfo() / files.get_info() methods. Information such as file name, type, and path is returned.
You can watch a directory for changes using the files.watchDir() method in JavaScript and files.watch_dir() method in Python.
Since events are tracked asynchronously, their delivery may be delayed.
It’s recommended not to collect or close watcher immediately after making a change.
You can enable recursive watching using the parameter recursive.
When rapidly creating new folders (e.g., deeply nested path of folders), events other than CREATE might not be emitted. To avoid this behavior, create the required folder structure in advance.
Sometimes, you may want to let users from unauthorized environments, like a browser, upload files to the sandbox.
For this use case, you can use pre-signed URLs to let users upload files securely.All you need to do is create a sandbox with the secure: true option. An upload URL will then be generated with a signature that allows only authorized users to upload files.
You can optionally set an expiration time for the URL so that it will be valid only for a limited time.
import { Sandbox } from 'e2b'// Start a secured sandbox (all operations must be authorized by default)const sandbox = await Sandbox.create(template, { secure: true })// Create a pre-signed URL for file upload with a 10 second expirationconst publicUploadUrl = await sandbox.uploadUrl( 'demo.txt', { useSignatureExpiration: 10_000, // optional },)// Upload a file with a pre-signed URL (this can be used in any environment, such as a browser)const form = new FormData()form.append('file', 'file content')await fetch(publicUploadUrl, { method: 'POST', body: form })// File is now available in the sandbox and you can read itconst content = sandbox.files.read('/path/in/sandbox')
Sometimes, you may want to let users from unauthorized environments, like a browser, download files from the sandbox.
For this use case, you can use pre-signed URLs to let users download files securely.All you need to do is create a sandbox with the secure: true option. A download URL will then be generated with a signature that allows only authorized users to access files.
You can optionally set an expiration time for the URL so that it will be valid only for a limited time.
import fs from 'fs'import { Sandbox } from 'e2b'// Start a secured sandbox (all operations must be authorized by default)const sandbox = await Sandbox.create(template, { secure: true })// Create a pre-signed URL for file download with a 10 second expirationconst publicUrl = await sandbox.downloadUrl( 'demo.txt', { useSignatureExpiration: 10_000, // optional },)// Download a file with a pre-signed URL (this can be used in any environment, such as a browser)const res = await fetch(publicUrl)const content = await res.text()