Delete Files
Updated at:
Deleting files is useful for cleaning up temporary inputs, caches, and generated outputs. It only affects the filesystem inside the current sandbox.
Delete a file or directory
Python example:
sandbox.files.remove("/tmp/project/output.log")TypeScript example:
await sandbox.files.remove("/tmp/project/output.log");Before deleting a directory, confirm the path to avoid removing the entire workspace by mistake:
Python example:
exists = sandbox.files.exists("/tmp/project/output.log")
if exists:
sandbox.files.remove("/tmp/project/output.log")TypeScript example:
const exists = await sandbox.files.exists("/tmp/project/output.log");
if (exists) {
await sandbox.files.remove("/tmp/project/output.log");
}Recommendations
If the full sandbox will be terminated when the task ends, you usually do not need to delete temporary files one by one. Proactive cleanup is mainly useful for long-lived sandboxes or when multiple tasks run in the same sandbox.
Is this page helpful?