# Upload data to sandbox - Documentation

> For the complete documentation index, see [llms.txt](/llms.txt). Markdown is available with `Accept: text/markdown` and `.md` URL variants.

Source: /docs/guides/sandbox-filesystem-upload

# Upload data to sandbox

You can use the `files.write()` method to upload data to the sandbox.

##

[​](#upload-single-file)

Upload single file

JavaScript & TypeScript

Python

```
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()
```

```
from novita_sandbox.code_interpreter import Sandbox

sandbox = Sandbox.create()

local_file_path = '../local-test-file'
with open(local_file_path, "rb") as file:
file_path_in_sandbox = '/tmp/test-file'
result = sandbox.files.write(file_path_in_sandbox, file)
print(result)

sandbox.kill()
```

##

[​](#upload-with-pre-signed-url)

Upload with pre-signed URL

Pre-signed upload URLs allow users to upload files securely from environments that do not hold Novita SDK credentials, such as web browsers.
Create the sandbox with the `secure: true` option, then use the SDK on your trusted backend to generate the upload URL. Return it only to users authorized by your application, and set a short expiration time. The URL acts as a temporary bearer credential until it expires.

JavaScript & TypeScript

Python

```
import { Sandbox } from 'novita-sandbox/code-interpreter'

const sandbox = await Sandbox.create({ secure: true })

const filePathInSandbox = '/tmp/test-file'

// Generate pre signature upload URL
const publicUploadUrl = await sandbox.uploadUrl(filePathInSandbox, {
useSignatureExpiration: 120, // optional, in seconds
})

// Simulate browser behavior
const form = new FormData()
form.append('file', new Blob(['file content']), 'test-file')

const uploadRes = await fetch(publicUploadUrl, {
method: 'POST',
body: form,
})
if (!uploadRes.ok) {
throw new Error(`Upload failed: ${uploadRes.status} ${await uploadRes.text()}`)
}

// SDK Read Back Verification
const result = await sandbox.files.read(filePathInSandbox)
console.log(result)

await sandbox.kill()
```

```
from pathlib import Path

import requests
from novita_sandbox.code_interpreter import Sandbox

sandbox = Sandbox.create(secure=True)

local_file_path = Path("../local-test-file")
file_path_in_sandbox = "/tmp/test-file"

# Generate pre signature upload URL
signed_url = sandbox.upload_url(
path=file_path_in_sandbox,
use_signature_expiration=120 # optional, in seconds
)

# Simulate browser behavior
with open(local_file_path, "rb") as f:
response = requests.post(
signed_url,
files={"file": (local_file_path.name, f)},
timeout=60,
)
response.raise_for_status()

# SDK Read Back Verification
result = sandbox.files.read(file_path_in_sandbox)
print(result)

sandbox.kill()
```

##

[​](#upload-directory-/-multiple-files)

Upload directory / multiple files

JavaScript & TypeScript

Python

```
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()
```

```
import os
from novita_sandbox.code_interpreter import Sandbox

sandbox = Sandbox.create()

def read_directory_files(directory_path):
files = []

for filename in os.listdir(directory_path):
file_path = os.path.join(directory_path, filename)

if os.path.isfile(file_path):
with open(file_path, "rb") as file:
files.append({
'path': file_path,
'data': file.read()
})
return files

local_directory_path = '../local-test-dir'
files = read_directory_files(local_directory_path)
print(files)

for file in files:
file['path'] = file['path'].replace('../local-test-dir', '/tmp')

result = sandbox.files.write_files(files)
print(result)

sandbox.kill()
```

Last modified on June 25, 2026
