删除文件用于清理临时输入、缓存和生成产物。它只影响当前沙箱内文件系统。
删除文件或目录
Python 示例:
sandbox.files.remove("/tmp/project/output.log")TypeScript 示例:
await sandbox.files.remove("/tmp/project/output.log");删除目录前建议先确认路径,避免误删整个工作区:
Python 示例:
exists = sandbox.files.exists("/tmp/project/output.log")
if exists:
sandbox.files.remove("/tmp/project/output.log")TypeScript 示例:
const exists = await sandbox.files.exists("/tmp/project/output.log");
if (exists) {
await sandbox.files.remove("/tmp/project/output.log");
}使用建议
如果任务结束后整个沙箱都会被终止,通常不需要逐个删除临时文件。只有在长生命周期沙箱或同一沙箱内执行多个任务时,才需要主动清理工作目录。
该文章对您有帮助吗?