Documentation Index
Fetch the complete documentation index at: https://novita.ai/docs/llms.txt
Use this file to discover all available pages before exploring further.
You can upload data to the sandbox using the files.write() method.
Upload single file
import fs from 'fs'
import { Sandbox } from 'novita-sandbox/code-interpreter'
const sandbox = await Sandbox.create()
// Read file from local filesystem
const localFilePath = '../local-test-file'
const content = fs.readFileSync(localFilePath, 'utf8')
// Upload file to sandbox
const filePathInSandbox = '/tmp/test-file'
const result = await sandbox.files.write(filePathInSandbox, content)
console.log(result)
await sandbox.kill()
Upload directory / multiple files
import fs from 'fs'
import path from 'path'
import { Sandbox } from 'novita-sandbox/code-interpreter'
const sandbox = await Sandbox.create()
const readDirectoryFiles = (directoryPath) => {
const files = fs.readdirSync(directoryPath);
const filesArray = files
.filter(file => {
const fullPath = path.join(directoryPath, file);
return fs.statSync(fullPath).isFile();
})
.map(file => {
const filePath = path.join(directoryPath, file);
return {
path: filePath,
data: fs.readFileSync(filePath, 'utf8')
};
});
return filesArray;
};
const localDirectoryPath = '../local-test-dir'
const files = readDirectoryFiles(localDirectoryPath);
console.log(files);
files.forEach(file => {
file.path = file.path.replace('../local-test-dir', '/tmp')
})
const result = await sandbox.files.write(files)
console.log(result)
await sandbox.kill()