Download files from the sandbox
Any file inside the sandbox can be downloaded using the downloadFile
/download_file
method.
Use case for downloading files
For example, the download file method is useful for downloading any files produced by LLM. You can let LLM generate and execute code inside the sandbox. This LLM-generated code might produce some files like charts, CSV files, or PDF files that you want to download to your machine.
import { Sandbox } from 'e2b'
import fs from 'node:fs'
const sandbox = await Sandbox.create({ template: 'base' })
const buffer = await sandbox.downloadFile('path/to/remote/file/inside/sandbox', 'buffer')
// Save file to local filesystem
fs.writeFileSync('path/to/local/file', buffer)
await sandbox.close()