Skip to content

/flags/deno/deno-run-permission-flags

deno run --allow-read, --allow-env, --allow-net: Deno permission flags

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
tool
Deno
command
deno run
flag
--allow-read, --allow-write, --allow-net, --allow-env, --allow-run, --allow-sys, --allow-ffi, --allow-import, -A
default
no permissions (deno run prompts in a terminal, fails otherwise)

Deno runs code without access to files, network, environment variables or subprocesses unless you grant it. Each capability has a flag: --allow-read, --allow-write, --allow-net, --allow-env, --allow-run, --allow-sys, --allow-ffi, --allow-import, and -A (--allow-all) grants everything. Without the flag, an interactive terminal shows a prompt; in scripts and CI the call fails with NotCapable: Requires read access to "config.json", run again with the --allow-read flag. Each flag can be scoped to specific paths, hosts or names.

Missing and granted permissions

bash
cat > config.json <<'EOF'
{ "name": "demo" }
EOF
cat > main.ts <<'EOF'
const mode = Deno.env.get("APP_MODE");
const cfg = JSON.parse(await Deno.readTextFile("config.json"));
console.log(`mode=${mode} name=${cfg.name}`);
EOF
export APP_MODE=production
echo "--- no flags"
npx --yes deno@2 run --no-prompt main.ts 2>&1 | grep NotCapable
echo "--- --allow-env=APP_MODE"
npx --yes deno@2 run --no-prompt --allow-env=APP_MODE main.ts 2>&1 | grep NotCapable
echo "--- --allow-env=APP_MODE --allow-read=config.json"
npx --yes deno@2 run --no-prompt --allow-env=APP_MODE --allow-read=config.json main.ts

Output

--- no flags
error: Uncaught (in promise) NotCapable: Requires env access to "APP_MODE", run again with the --allow-env flag
--- --allow-env=APP_MODE
error: Uncaught (in promise) NotCapable: Requires read access to "config.json", run again with the --allow-read flag
--- --allow-env=APP_MODE --allow-read=config.json
mode=production name=demo

Deno stops at the first operation that is not allowed, so the errors appear one at a time. --no-prompt makes the run behave as in CI even in a terminal. Since Deno 2 the error class is Deno.errors.NotCapable (Deno 1 used PermissionDenied).

The flags

FlagGrantsScoped example
--allow-read (-R)File system reads--allow-read=./data,/etc/hosts
--allow-write (-W)File system writes--allow-write=./out
--allow-net (-N)Network access, including listening--allow-net=api.example.com,0.0.0.0:8000
--allow-env (-E)Reading and setting environment variables--allow-env=PORT,HOME
--allow-runRunning subprocesses--allow-run=git,curl
--allow-sys (-S)System information (hostname, OS release...)--allow-sys=hostname
--allow-ffiLoading native libraries--allow-ffi=./libfoo.so
--allow-import (-I)Importing code from remote hosts--allow-import=deno.land
-A, --allow-allEverythingnone (avoid in production)

--deny-read, --deny-net and the other --deny-* flags take precedence over the matching --allow-* flag, so you can allow a directory but exclude one file. Permissions can also be declared in deno.json and selected with -P (--permission-set).

Sources