Skip to main content
Most real workloads need data. This tutorial shows you how to get files into a sandbox, process them, and get results back out. You’ll learn three methods and when to use each one.

Method comparison

Prerequisites

Method 1: copy_in / copy_out

The most common approach. Upload a file, process it, download the results.
file_transfer.py
When to use: Dynamic per-request files — scripts, input data, configuration that varies across runs.

Method 2: Volume mounts

Mount a host directory directly into the box. Files are shared in real time — no explicit copy step needed.
volume_mount.py
When to use: Shared datasets or configuration that multiple boxes need access to. Use read-only mode for input data to prevent accidental modification.
Volume mounts give the guest direct access to host files. Always use read-only mode (True) for input data. Only use False for designated output directories.

Method 3: Inline data via base64

For small payloads (under ~1 MB), you can send data through a shell command without touching the filesystem.
inline_base64.py
When to use: Trivially small payloads where you want to avoid the overhead of copy_in. Not suitable for binary files or anything over ~1 MB.

Putting it together

Here’s a realistic workflow: upload a CSV, run analysis code on it, and download the results.
full_workflow.py
Use copy_in/copy_out for dynamic per-request files. Use volume mounts for shared datasets. Use inline base64 only for trivially small payloads.

What’s next?

Connect to an LLM

Let an LLM generate code and run it in your sandbox automatically.

AI agent integration

Production patterns: security presets, concurrency, timeout handling, and resource limits.