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')