Skip to main content
You can use the files.read() method to download data from the sandbox.
import fs from 'fs'
import { Sandbox } from 'novita-sandbox/code-interpreter'

const sandbox = await Sandbox.create()

// Create a file in the sandbox for testing
const filePathInSandbox = '/tmp/test-file'
await sandbox.files.write(filePathInSandbox, "test-file-content")

// Read file from sandbox
const content = await sandbox.files.read(filePathInSandbox)

// Write file to local filesystem
const localFilePath = './local-test-file'
fs.writeFileSync(localFilePath, content)

await sandbox.kill()

Download with pre-signed URL

Pre-signed download URLs also allow users to download files securely from unauthorized environments, such as web browsers. You can use the secure: true option to create a sandbox with a pre-signed download URL. Only authorized users can access files through the URL. You can optionally set an expiration time for the URL to limit its validity.
import fs from 'fs'
import { Sandbox } from 'novita-sandbox/code-interpreter'

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

// Create a test file in the sandbox (requires SDK authentication)
const filePathInSandbox = '/tmp/test-file'
await sandbox.files.write(filePathInSandbox, 'test-file-content')

// Generate pre signed download URL (valid for 120 seconds, optional)
const publicDownloadUrl = await sandbox.downloadUrl(filePathInSandbox, {
  useSignatureExpiration: 120, // optional
})

// Simulate "browser/unauthorized environment": without API key, directly GET download
const res = await fetch(publicDownloadUrl)
if (!res.ok) {
  throw new Error(`Download failed: ${res.status} ${await res.text()}`)
}
const content = await res.text()

// Write to local file
const localFilePath = './local-test-file'
fs.writeFileSync(localFilePath, content)
console.log(content)

await sandbox.kill()
Last modified on June 5, 2026