import fs from 'fs'
import { Sandbox } from '@e2b/code-interpreter'
// 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 expiration
const 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 it
const content = fs.readFileSync('demo.txt')