Python "PermissionError: [Errno 13] Permission denied" in CI
PermissionError: [Errno 13] Permission denied is raised when the OS refuses an open, write, or execute because the current user lacks the required permission on the path.
What this error means
A step fails with "PermissionError: [Errno 13] Permission denied: '/var/lib/app/cache'" when opening, writing, or executing a path.
python
PermissionError: [Errno 13] Permission denied: '/var/lib/app/data.db'Common causes
Writing to a directory owned by another user
A system path or a volume created by a different UID is not writable by the CI user.
Executing a file without the execute bit
A script was checked out without +x and the code tried to run it directly.
How to fix it
Write to a writable location or fix the mode
- Point output at a path the CI user owns, such as the workspace or a tmp dir.
- Add the execute bit (
chmod +x) to scripts that must run directly. - If a step must touch a protected path, run it with the right user or adjust ownership in setup.
Python
import tempfile, pathlib
out = pathlib.Path(tempfile.gettempdir()) / "app-cache"
out.mkdir(parents=True, exist_ok=True)How to prevent it
- Default to workspace- or tmp-relative paths for writes.
- Track the execute bit on scripts in git.
- Avoid hard-coding root-owned system paths.
Related guides
Python "IsADirectoryError: [Errno 21]" in CIFix "IsADirectoryError: [Errno 21] Is a directory" in CI - code tried to open or read a path as a file but it…
Python "FileNotFoundError" opening a missing path in CIFix "FileNotFoundError: [Errno 2] No such file or directory" in CI - code opened a path that does not exist o…
Python "FileExistsError: [Errno 17]" in CIFix "FileExistsError: [Errno 17] File exists" in CI - mkdir or an exclusive open failed because the target al…