LelantosLelantos
Filesystem

Download Files

Download files from sandbox filesystem.

Overview

Download files from a running sandbox to retrieve outputs, logs, generated artifacts, or any file from the sandbox filesystem.

Downloading a File

const data = await sandbox.downloadFile("/home/user/output.txt");

// data is an ArrayBuffer
const text = new TextDecoder().decode(data);
console.log(text);
curl "https://SANDBOX_ID.lelantos.ai/files?path=/home/user/output.txt" \
  -H "X-API-Key: lel_your_key_here" \
  --output output.txt

Decoding Text Content

The downloadFile method returns an ArrayBuffer. To work with text content, use TextDecoder:

const data = await sandbox.downloadFile("/home/user/results.json");
const text = new TextDecoder().decode(data);
const results = JSON.parse(text);

console.log("Results:", results);

Downloading Binary Files

For binary files (images, PDFs, archives), write the ArrayBuffer directly to disk:

import { writeFileSync } from "fs";

// Download a generated chart
const chartData = await sandbox.downloadFile("/home/user/chart.png");
writeFileSync("./chart.png", Buffer.from(chartData));

// Download a zip archive
const archiveData = await sandbox.downloadFile("/home/user/results.zip");
writeFileSync("./results.zip", Buffer.from(archiveData));

Listing Files

To see what files exist before downloading, run a command:

const result = await sandbox.commands.run("ls -la /home/user/");
console.log(result.stdout);

Example: Run a Script and Download Output

// Upload a script
await sandbox.uploadFile("/home/user/analyze.py", `
import json

results = {"status": "complete", "items_processed": 1500}
with open("/home/user/results.json", "w") as f:
    json.dump(results, f)
`);

// Run the script
await sandbox.commands.run("python /home/user/analyze.py");

// Download the output
const data = await sandbox.downloadFile("/home/user/results.json");
const results = JSON.parse(new TextDecoder().decode(data));
console.log(results.items_processed); // 1500

On this page