Skip to content

TypeScript Commands and Files

InterfacePurpose
runtime.exec(command, options?)Run a buffered command and return exit code, stdout, and stderr.

Run an argv-style command:

const result = await runtime.exec(["sh", "-lc", "pwd && ls -la"], {
timeoutSecs: 30,
});
console.log(result.exit_code);
console.log(result.stdoutText);
console.error(result.stderrText);

Pass a string when you want shell behavior:

await runtime.exec("cd /tmp && echo hello > message.txt");
InterfacePurpose
runtime.files.write(path, data)Write bytes or text to one runtime file.
runtime.files.read(path)Read one runtime file as Uint8Array.
runtime.files.readText(path)Read one runtime file and decode it as text.
runtime.files.upload(local, remote)Upload one file or directory.
runtime.files.download(remote, local)Download one file or directory.
await runtime.files.write("/tmp/message.txt", "hello");
const text = await runtime.files.readText("/tmp/message.txt");
console.log(text);
await runtime.files.upload("./local-file.txt", "/tmp/local-file.txt");
await runtime.files.download("/tmp/local-file.txt", "./downloaded-file.txt");

Directory upload is supported by recursively writing files into the runtime.