Guides

Deno permissions

Configure permissions for environment variables and the current directory.

Deno permissions

Deno protects some APIs with explicit permissions. A capability can therefore exist while remaining inaccessible to the current process.

Environment variables

const runtime = createRuntimeAdapter()
const token = runtime.getEnv('API_TOKEN')

Allow all environment variables with deno run --allow-env app.ts, or selected variables with:

deno run --allow-env=API_TOKEN,NODE_ENV app.ts

Calling runtime.getEnv() without a key requires access to all returned variables.

Current directory

Depending on the Deno version and configuration, runtime.cwd() may require read access:

deno run --allow-read=. app.ts

oruntime behavior

Permission denial is never converted to an empty value. It throws PermissionDeniedError:

try {
  console.log(runtime.getEnv('API_TOKEN'))
} catch (error) {
  if (error instanceof PermissionDeniedError) {
    console.error(`Missing permission for ${error.capability}`)
  }
}

The capability remains true because Deno exposes the API; permission answers whether this program may use it.

Recommendations

  • Grant only required permissions.
  • Avoid -A in sensitive environments.
  • Handle PermissionDeniedError separately from a missing value.
  • Document required permissions in your application README.