Grant Deno minimum permissions: scope file, network, and environment access
Deno denies filesystem, network, environment-variable, and subprocess access by default. Grant only what a program needs and narrow it to paths, hosts, or variable names. Code and dependencies running with the same privilege share that access, so flags alone do not isolate untrusted code. This guide follows official Deno runtime docs checked 2026-11-20.
Deno denies filesystem, network, environment-variable, and subprocess access by default. Grant only what a program needs and narrow it to paths, hosts, or variable names. Code and dependencies running with the same privilege share that access, so flags alone do not isolate untrusted code. This guide follows official Deno runtime docs checked 2026-11-20.
Map operations to permissions
The illustrative program reads ./data/input.json, reads API_KEY, and sends a request to api.example.com. That host is a documentation example; this code was not run.
const apiKey = Deno.env.get("API_KEY");
const data = await Deno.readTextFile("./data/input.json");
const response = await fetch("https://api.example.com/ingest", {
method: "POST",
headers: { authorization: `Bearer ${apiKey}` },
body: data,
});
console.log(response.status);Run without grants in noninteractive mode:
deno run --no-prompt main.tsThe file, environment, or network operation should fail with NotCapable. A terminal can show a permission prompt, but --no-prompt denies rather than approving it. Read each request and grant access only when the program needs it.
Grant only the required scope
deno run --no-prompt --allow-read=./data --allow-net=api.example.com --allow-env=API_KEY main.ts--allow-read=./data permits reads under that directory, rather than all files.
--allow-net=api.example.com permits network access to that host. A hostname does not automatically include subdomains; specify a port if needed.
--allow-env=API_KEY allows reading only that variable. Provide secret values through a secure environment setup; do not hard-code them in commands or source control.
If another resource is needed, Deno may raise NotCapable again. Inspect the requested resource and add only that exact path, host, or variable. A matching --deny-* overrides --allow-*.
Understand the boundary
The initial static module graph is loaded before code runs and follows different permission checks; actual file and network operations by those modules still require runtime permission. Dynamic imports with runtime-computed specifiers may need read or import permission.
All code and dependencies on the same thread share the granted privilege. -A/--allow-all disables the sandbox. Be especially cautious with --allow-run: child processes do not inherit the parent's restricted permission set. --allow-ffi loads native code that can access operating-system resources beyond Deno's JavaScript checks. Untrusted code needs additional isolation such as an OS sandbox or VM.
Verify
Run with --no-prompt and no grants to observe denial. Then add only the required scopes and confirm the intended operation works; in a separate test environment, confirm out-of-scope paths and hosts remain denied. Remove unused grants. Consider Deno.permissions.revoke when access is no longer needed. The example was not executed and made no real request. Check the permission docs for your installed Deno version.
References
[Deno security and permissions](https://docs.deno.com/runtime/fundamentals/security/)
[deno run CLI](https://docs.deno.com/runtime/reference/cli/run/)
[Deno permissions reference](https://docs.deno.com/runtime/reference/permissions/)
[Run code in Deno](https://docs.deno.com/runtime/run/)