Skip to content
Home

File Operations & Transfer

Filesystem operations run through the sandbox runtime API. SDKs hide runtime auth, Connect RPC headers, and upload/download route differences.

await sandbox.files.write("/root/workspace/hello.txt", "hello\n");
const text = await sandbox.files.read("/root/workspace/hello.txt");
console.log(text);
await sandbox.files.makeDir("/root/workspace/app");
await sandbox.files.write("/root/workspace/app/index.html", "<h1>Hello</h1>");
const entries = await sandbox.files.list("/root/workspace/app");
console.log(entries);

For fast iteration, read local files in your application and write them into the sandbox:

const html = await fs.promises.readFile("./index.html", "utf8");
await sandbox.files.write("/root/workspace/frontend/index.html", html);

For reusable source and dependency setup, upload local files during template build with Template.copy(...) instead of uploading into every new sandbox.

Use SDK helpers where possible. When debugging raw runtime traffic, the common routes are:

RoutePurpose
GET {envdUrl}/file?path=<path>Read raw file bytes.
POST {envdUrl}/file?path=<path>Write raw file bytes.
GET {envdUrl}/files/content?path=<path>Read file content as a structured response.
POST {envdUrl}/filesUpload multipart content.
POST {envdUrl}/files/batchWrite multiple files.
POST {envdUrl}/files/composeCompose output from multiple source files.

All routes require X-Access-Token: <envdAccessToken>.

Directory watchers are exposed through the runtime filesystem surface when enabled in the target SDK/runtime. Use watchers when an agent writes output files and the orchestrator needs to react.

const watcher = await sandbox.files.watchDir("/root/workspace/output", {
recursive: true,
});
for await (const event of watcher) {
console.log(event.type, event.path);
}
RuleWhy it matters
Prefer absolute pathsAvoid ambiguity around template workdir.
Use mounted paths for durable filesPersistence is controlled by volumeMounts[].path, not by workdir.
Treat ephemeral as sandbox-lifetime storageFiles disappear when the sandbox is deleted.
Keep artifacts out of logsGenerated files may contain secrets or user data.
Storage typePersistence behavior
ephemeralSandbox lifetime only.
nfsShared NFS path.
blockPVC-backed volume.
objectSynced to object-backed storage, depending on runtime sync policy.

For object-backed storage, wait for the runtime sync/flush behavior your template documents before deleting the sandbox.