Deno — permission denied for network or file access
Deno throws PermissionDenied because the script accesses a resource without the required --allow flag, unlike Node.js which grants permissions by default.
Symptoms
- error: PermissionDenied: Requires net access to "example.com"
- error: PermissionDenied: Requires read access to "/etc/hosts"
- The script works with --allow-all but not without it
Possible causes
- The script makes network requests without --allow-net
- The script reads or writes files without --allow-read or --allow-write
- The script uses env vars without --allow-env
Diagnosis steps
Run with --allow-all to confirm it is a permission issue
deno run --allow-all script.tsInterpretation
If it works, the error is purely a missing permission flag.
Identify the specific permission needed
deno run script.ts 2>&1 | head -1Interpretation
The error message names the exact permission and resource.
Root cause
Deno is secure by default; every network, file, env, or subprocess access requires an explicit permission flag, and the runtime blocks the operation without it.
Fix
Add the specific --allow-flag for the resource, or use a permission prompt with --prompt to grant interactively. For production, list only the needed permissions.
Verify the fix
Run the script with the specific permission flags and confirm it completes without a PermissionDenied error.
Symptom walkthrough
Deno throws PermissionDenied because the script accesses a resource without the required –allow flag, unlike Node.js which grants permissions by default. The error appears in production but may not surface in local development because the conditions that trigger it depend on the deployment environment or runtime configuration. Understanding the full symptom set helps distinguish this issue from similar errors.
Diagnosis in practice
Follow the diagnosis steps in the frontmatter to isolate the cause. Each step includes a command and an interpretation of the output. The goal is to narrow down whether the issue is in the configuration, the runtime, or the application code. Reproduce the error in a minimal setup before applying a fix.
Root cause
Deno is secure by default; every network, file, env, or subprocess access requires an explicit permission flag, and the runtime blocks the operation without it.
Fix
Add the specific –allow-flag for the resource, or use a permission prompt with –prompt to grant interactively. For production, list only the needed permissions. After applying the fix, monitor the system to confirm the error does not recur under load or in different environments.
Verification
Run the script with the specific permission flags and confirm it completes without a PermissionDenied error. If the verification passes, the fix is confirmed; if not, re-examine the diagnosis steps for missed contributing factors.
Diagnostic commands
Run these commands to reproduce and diagnose the issue:
deno run --allow-all script.ts
deno run script.ts 2>&1 | head -1