Get started
Model APIs
- Overview
- LLM
- Image, Audio and Video
- Integration
Agent Sandbox
- Overview
- Quickstart
- E2B Compatible
- Sandbox
- Template
- Filesystem
- Commands
- CLI
GPUs
- Overview
- GPU Instance
- Serverless GPUs
- Template Guide
Observability
Filesystem
Upload data to sandbox
You can upload data to the sandbox using the files.write()
method.
Upload single file
Copy
Ask AI
import fs from 'fs'
import { Sandbox } from '@e2b/code-interpreter'
const sandbox = await Sandbox.create()
// Read file from local filesystem
const content = fs.readFileSync('/local/path')
// Upload file to sandbox
await sandbox.files.write('/path/in/sandbox', content)
Upload directory / multiple files
Copy
Ask AI
import fs from 'fs'
import path from 'path'
import { Sandbox } from '@e2b/code-interpreter'
const sandbox = await Sandbox.create()
// Read all files in the directory and store their paths and contents in an array
const readDirectoryFiles = (directoryPath) => {
// Read all files in the local directory
const files = fs.readdirSync(directoryPath);
// Map files to objects with path and data
const filesArray = files
.filter(file => {
const fullPath = path.join(directoryPath, file);
// Skip if it's a directory
return fs.statSync(fullPath).isFile();
})
.map(file => {
const filePath = path.join(directoryPath, file);
// Read the content of each file
return {
path: filePath,
data: fs.readFileSync(filePath, 'utf8')
};
});
return filesArray;
};
// Usage example
const files = readDirectoryContents('/local/dir');
console.log(files);
// Output example:
// [
// { path: '/local/dir/file1.txt', data: 'File 1 contents...' },
// { path: '/local/dir/file2.txt', data: 'File 2 contents...' },
// ...
// ]
await sandbox.files.write(files)
Was this page helpful?
Assistant
Responses are generated using AI and may contain mistakes.