创建目录用于准备项目工作区、日志目录或中间结果目录。
创建目录
Python 示例:
sandbox.files.make_dir("/tmp/project/src")
sandbox.files.write("/tmp/project/src/main.py", "print('hello')\n")TypeScript 示例:
await sandbox.files.makeDir("/tmp/project/src");
await sandbox.files.write("/tmp/project/src/main.py", "print('hello')\n");Python SDK 使用 make_dir(),TypeScript SDK 使用 makeDir()。该方法会创建缺失的中间目录。目录已存在时,SDK 会返回对应结果,不需要业务侧提前执行 mkdir -p。
使用建议
建议为每个任务创建独立工作目录,例如 /tmp/tasks/<task-id>。这样可以降低文件名冲突,也方便任务结束后整体清理。
该文章对您有帮助吗?