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, prefer a prepared official template or a pinned concrete tpl-.... Projects with template build access can also preinstall dependencies through the template build flow.

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.
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 behaviorBest use
ephemeralSandbox lifetime only.Temporary files and generated artifacts that can be discarded.