Upload & downloads files

E2B Sandbox allows you to upload and downloads file to and from the Sandbox.

An alternative way to get your data to the sandbox is to create a custom sandbox template.

Upload file

import { Sandbox } from '@e2b/code-interpreter'

// Read local file
const content = fs.readFileSync('/local/file')

const sbx = await Sandbox.create()
// Upload file to the sandbox to path '/home/user/my-file'
await sbx.files.write('/home/user/my-file', content)

Upload multiple files

Currently, if you want to upload multiple files, you need to upload each one of the separately. We're working on a better solution.

import { Sandbox } from '@e2b/code-interpreter'

// Read local files
const fileA = fs.readFileSync('/local/file/a')
const fileB = fs.readFileSync('/local/file/b')

const sbx = await Sandbox.create()
// Upload file A to the sandbox to path '/home/user/my-file-a'
await sbx.files.write('/home/user/my-file-a', content)
// Upload file B to the sandbox to path '/home/user/my-file-b'
await sbx.files.write('/home/user/my-file-b', content)

Upload directory

We currently don't support an easy way to upload a whole directory. You need to upload each file separately.

We're working on a better solution.


Download file

To download a file, you need to first get the file's content and then write it to a local file.

import { Sandbox } from '@e2b/code-interpreter'

const sbx = await Sandbox.create()
// Download file from the sandbox to path '/home/user/my-file'
const content = await sbx.files.read('/home/user/my-file')
// Write file to local path
fs.writeFileSync('/local/file', content)

Download multiple files

To download multiple files, you need to download each one of them separately from the sandbox.

We're working on a better solution.

import { Sandbox } from '@e2b/code-interpreter'

const sbx = await Sandbox.create()
// Download file A from the sandbox to path '/home/user/my-file'
const contentA = await sbx.files.read('/home/user/my-file-a')
// Write file A to local path
fs.writeFileSync('/local/file/a', contentA)

// Download file B from the sandbox to path '/home/user/my-file'
const contentB = await sbx.files.read('/home/user/my-file-b')
// Write file B to local path
fs.writeFileSync('/local/file/b', contentB)

Download directory

We currently don't support an easy way to download a whole directory. You need to download each file separately.

We're working on a better solution.