The PermissionError: [Errno 13] Permission denied usually means your Python code (or sub-agent) doesn’t have the proper rights or file path access to write to the target file.
Here are the most common causes and fixes:
Make sure your sub-agent is writing to a path it actually has access to.
file_path = "/path/to/output.txt"
with open(file_path, "w") as f:
f.write("Hello World!")
If this path is inside a restricted system folder (e.g., /root, C:\Program Files, etc.), you’ll get Permission denied.
Fix:
Use a user-writable path like /tmp, ./data/, or os.getcwd()
Example:
import os
file_path = os.path.join(os.getcwd(), "output.txt")
with open(file_path, "w") as f:
f.write("Works fine!")