Read and write files
files.write creates a file or replaces its contents. Missing parent directories are created automatically. files.read returns text by default.
Write and read one file
mjs
import { Sandbox } from "@abox-dev/sdk";
const sandbox = await Sandbox.create();
try {
await sandbox.files.write("/tmp/message.txt", "hello from AgentBox");
const message = await sandbox.files.read("/tmp/message.txt");
console.log(message);
} finally {
await sandbox.kill();
}Pass { format: "bytes" } in JavaScript or format="bytes" in Python for binary data. Both SDKs also support streamed reads for large files.
Write several files
Use writeFiles in JavaScript or write_files in Python to send several files in one operation:
mjs
import { Sandbox } from "@abox-dev/sdk";
const sandbox = await Sandbox.create();
try {
await sandbox.files.writeFiles([
{ path: "/tmp/notes/first.txt", data: "First note" },
{ path: "/tmp/notes/second.txt", data: "Second note" },
]);
const entries = await sandbox.files.list("/tmp/notes");
console.log(entries.map((entry) => entry.name).join(", "));
} finally {
await sandbox.kill();
}files.list returns the entries in a directory. Use makeDir / make_dir, rename, and remove for the other common filesystem operations.