Overview

Files

Read a file#

import { Sandbox } from 'e2b'
 
const sandbox = await Sandbox.create()
const fileContent = await sandbox.files.read('/path/to/file')
from e2b import Sandbox
 
sandbox = Sandbox.create()
file_content = sandbox.files.read('/path/to/file')

Write one file#

await sandbox.files.write('/path/to/file', 'file content')
sandbox.files.write('/path/to/file', 'file content')

Write many files#

In Python, multiple files go through write_files(); write() takes a single file. This changed in SDK v2 — see Migrating to v2.

await sandbox.files.write([
  { path: '/path/to/a', data: 'file content' },
  { path: '/another/path/to/b', data: 'file content' },
])
sandbox.files.write_files([
    {"path": "/path/to/a", "data": "file content"},
    {"path": "/another/path/to/b", "data": "file content"},
])

Upload a local file#

Read the file on your machine and write its bytes into the sandbox. The returned object carries the path it landed at.

import fs from 'fs'
 
const content = fs.readFileSync('dataset.csv')
const info = await sandbox.files.write('/home/user/dataset.csv', content)
console.log(info.path)
with open("dataset.csv", "rb") as f:
    info = sandbox.files.write("/home/user/dataset.csv", f)
print(info.path)

Next#

Was this page helpful?