Per-package permissions
Ende 2026.12.01
Per-package permissions (the isolate key) are new in this release.
Every module in a program shares the program's permissions. A CSV parser you
import runs with your app's --allow-net and --allow-read, though it needs
neither. The isolate key in ende.json names dependencies to run in a sandbox
of their own: a worker with only the permissions you grant it, and never more
than the app has.
The unit is a package or a folder, not a single module: modules inside one sandbox share everything with each other. A module that a sandboxed package imports runs inside that sandbox too, even when no rule matches it. Only code that the app imports itself, and that no rule matches, runs in the app, with all of the app's permissions.
To run code with permissions the app itself doesn't have, such as a plugin, use an extension instead.
Sandbox a dependency
Say the app vendors a small CSV library in vendor/csv/:
export function parse(text: string): string[][] {
return text.trim().split("\n").map((line) => line.split(","));
}
export async function peek(path: string): Promise<string> {
return await Ende.readTextFile(path);
}A rule with an empty grant runs it with no permissions at all:
{
"isolate": {
"./vendor/csv/": { "permissions": [] }
}
}The app imports it as before. Calls into the sandbox return promises:
import { parse, peek } from "./vendor/csv/mod.ts";
const text = await Ende.readTextFile("./data/people.csv");
console.log(await parse(text));
console.log(await peek("./data/people.csv"));$ ende run --allow-read main.ts
Recorded isolate["./vendor/csv/"] in ende.lock; it will run with: no permissions
[ [ "name", "age" ], [ "Ada", "36" ] ]
error: Uncaught (in promise) NotCapable: ./vendor/csv/: Requires read access to "./data/people.csv"; grant it in ende.json under isolate["./vendor/csv/"].permissions.read
The app reads the file with its own --allow-read; the library, asked to read
the same file, is denied. The first run recorded the rule in ende.lock (see
Approving changes).
Rules
Each key under isolate is a matcher:
| Matcher | Matches |
|---|---|
jsr:@scope/name |
every version and entry of the package |
https://host/path/ |
every module under that URL (ends in /) |
https://host/path/mod.ts |
that one module |
./dir/ or ../dir/ |
every module in that folder (ends in /) |
file:///abs/dir/ |
every module in that folder (ends in /) |
Rules match modules by their resolved specifier, after the import map, so remapping an import doesn't take it out of its sandbox. A module that several rules match belongs to the most specific one: the deepest folder or the longest URL prefix, whatever their order. A rule that matches nothing in a run's module graph prints a warning:
Warning isolate["./vendor/fast/"] matches no module in the graph, so it sandboxes nothing unless a computed import() loads one. Rules match resolved specifiers, after the import map.
A computed import(), whose specifier is only known when it runs, isn't in the
graph. A module it loads still runs in the sandbox of the rule that matches it,
so the warning doesn't mean the rule is unused.
Two keys that name the same modules, such as ./vendor/a/ and ./vendor//a/,
are an error for every command that reads the rules, ende ci among them:
error: isolate["./vendor/a/"] and isolate["./vendor//a/"] are the same rule, spelled two ways. Keep one of them.
A folder rule can't hold the app itself (the folder of ende.json or above),
and an isolate rule can't match an extension's code. The
ende.json reference lists every field
and the errors for each.
Workspaces and linked packages
Only the rules in the workspace root's ende.json apply. isolate in a
workspace member's ende.json is an error for every command that would apply
it, ende run, ende check, ende install and ende ci among them:
$ ende run mod.ts
error: "isolate" can only be specified in the workspace root ende.json file. Move the rules from file:///Users/me/app/member/ende.json to file:///Users/me/app/ende.json, with folder matchers rewritten relative to it.
A package the root lists under links may have isolate rules of its own.
They don't apply: Ende ignores them with a warning, which --quiet hides, and
the linked package's code runs unsandboxed. To sandbox it, add folder rules to
the root's ende.json, with paths relative to the root:
$ ende run main.ts
Warning "isolate" in a linked package's ende.json doesn't apply: a linked package's rules are ignored. To sandbox its code, add rules to file:///Users/me/app/ende.json, with paths relative to that file.
at file:///Users/me/linked/ende.json
A folder the app reaches only through an import map path, such as
"lib/": "../third_party/lib/", is another project, not a linked package. The
isolate rules in its own ende.json don't apply either, and nothing warns
about them.
A folder inside the workspace with its own "workspace" key, or one that isn't
listed as a member, would make Ende stop looking for the root there and skip the
root's rules. So Ende refuses to run in it when an outer ende.json that
declares isolate (or extensions) lists the folder, lists a member inside it,
or has a folder rule inside it. The error names the configs to fix:
$ ende run mod.ts
error: file:///Users/me/app/ende.json declares "isolate" for code in file:///Users/me/app/member/ (its rule isolate["./member/vendor/x/"] names a folder in it), but there Ende uses file:///Users/me/app/member/ende.json as the workspace root, so they would not apply. Remove the "workspace" key from file:///Users/me/app/member/ende.json and list those folders, with the members they listed, in the "workspace" of file:///Users/me/app/ende.json, or pass --config /Users/me/app/ende.json. To run it on its own, without those rules, pass --config /Users/me/app/member/ende.json.
A project nested inside a member, which nothing lists, still runs on its own.
A member can also be a symlink to a folder outside the workspace. Ende finds
config files from a folder's real path, so after cd into the link it wouldn't
see the root's ende.json. On macOS and Linux, Ende also checks the path you
came in by, from the shell's $PWD, and refuses to run when the root's rules
would cover the folder:
$ cd /Users/me/app/member
$ ende run main.ts
error: file:///Users/me/app/ende.json declares "isolate" for code in file:///Users/me/app/member/ (its rule isolate["./member/vendor/x/"] names a folder in it), but /Users/me/app/member is a link to /Users/me/shared/member, and Ende finds config files from the real folder, so they would not apply. Put the folder itself at /Users/me/app/member instead of a link to it (a link from /Users/me/shared/member to it keeps that path working). To run it on its own, without those rules, pass --config /Users/me/shared/member/ende.json.
Move the folder into the workspace, and link to it from its old place if other
projects need that path. A shell or launcher that doesn't set $PWD to the
folder leaves Ende unable to tell, and the member then runs on its own, without
the root's rules.
Rules apply to the project Ende finds, and ende run looks for ende.json
starting from the folder of the file it runs. So ende run ../tools/main.ts,
run from the app's root, uses the config in or above ../tools (if there is
one) and none of the app's rules, even for app modules the script imports. That
is by design, not a way around the rules: they keep the app's dependencies in
check, and whoever picks what to run can already pass --no-config. Give a
script outside the app rules in its own ende.json, or keep it inside the app.
Granting permissions
permissions is required: [] grants nothing, a list of names grants each
whole kind, and an object grants scoped permissions like a
permission set, with relative paths
resolved against ende.json. write is the exception: a sandbox can only be
granted named folders of data. ["write"], ["all"] and {"write": true} are
errors, since the sandbox could then rewrite the app:
{
"isolate": {
"./vendor/csv/": { "permissions": { "read": ["./data"] } }
}
}A sandbox gets the grant, narrowed by the app's own permissions. A grant the app doesn't have gives a warning when the sandbox starts and is denied when it is used:
$ ende run peek_data.ts
Warning isolate["./vendor/csv/"] grants permissions the app itself doesn't have. A sandbox never gets more than the app, so using them will be denied:
read "/Users/me/app/data"
error: Uncaught (in promise) NotCapable: ./vendor/csv/: Requires read access to "./data/people.csv", which the app itself isn't allowed. isolate["./vendor/csv/"] can only narrow the app's permissions; run again with the --allow-read flag
A local module the sandboxed package imports from outside its own folder loads
with the sandbox's permissions, so the rule needs read for it, even when the
app runs with -A. Remote and jsr: modules load without it.
The narrowing keeps working while the app runs. The app's deny flags apply to
the sandbox, and an Ende.permissions.revoke() in the app reaches it too. A
revoke of one path removes only the app's grant entries that cover it, so under
a blanket --allow-read it changes nothing for the app or the sandbox (see
Adjusting permissions at runtime).
-A doesn't widen a sandbox, and nothing in a sandbox prompts:
$ ende run -A peek_secret.ts
error: Uncaught (in promise) NotCapable: ./vendor/csv/: Requires read access to "./secret.txt"; grant it in ende.json under isolate["./vendor/csv/"].permissions.read
A permission broker can deny a sandbox's request, but its "allow" never widens a sandbox.
Manifests
A package may say what it needs with a manifest in its entry module, the same form extensions use. Unlike for an extension, it is optional. When there is one, the sandbox gets the grant intersected with the manifest of every entry the app imports, so a manifest can only narrow:
export const manifest = {
permissions: { env: ["MODE"] }
};$ ende run -A main.ts
Recorded isolate["./vendor/tool/"] in ende.lock; it will run with: env MODE
NotCapable: ./vendor/tool/: Requires env access to "HOME", which the manifest of ./vendor/tool/mod.ts doesn't request. isolate["./vendor/tool/"]'s grant in ende.json allows it, but a sandbox gets only what its packages' manifests ask for
What crosses the boundary
The sandboxed package runs in another worker, so values are passed, not shared:
- Functions are called async: each call returns a promise.
- Classes cross as handles.
newreturns a promise of the instance's handle, and its methods and static methods are async too. Getters and setters are left out. - Constants are copied when the sandbox starts.
letandvarexports can't be imported from outside the sandbox, since their value can change.ende checkreports this too.- Arguments and results are copied. An object with methods, or a function, crosses as a handle whose calls run where the object lives.
import { Counter, firstLine, shout, VERSION } from "./vendor/kit/mod.ts";
console.log(VERSION);
console.log(await shout("hello"));
const counter = await new Counter();
await counter.increment();
console.log(await counter.increment());
// The callback runs in the app, with the app's permissions.
console.log(await firstLine((path) => Ende.readTextFile(path)));$ ende run --allow-read main.ts
Recorded isolate["./vendor/kit/"] in ende.lock; it will run with: no permissions
1.0.0
HELLO
2
first
vendor/kit/ is granted nothing, yet firstLine read a file: through the
callback, which ran in the app. A function you pass into a sandbox hands over
what it does with the app's permissions. Pass only functions that do what the
sandbox needs.
Only the app's own code crosses into a sandbox as a handle. An object whose
methods are Ende's, such as Ende, an FsFile or a Request, is refused at
the call:
$ ende run --allow-read passende.ts
error: Uncaught (in promise) TypeError: args[0].test is a method of Ende's own code, which isn't the app's own code; pass a function that does what the sandbox needs instead
An error thrown by the sandbox keeps its stack, message and name, and a
built-in error class, such as TypeError or Ende.errors.NotFound, keeps its
class. A class of the package's own arrives as a plain Error with that class's
name, and its cause isn't kept. An error thrown into a sandbox, by an app
callback, keeps only its name, message and cause.
instanceof against a class imported from a sandbox is always false, and a
class that extends one doesn't work.
ende check and the editor see the sandboxed types: functions return promises,
and an export that can't cross is an error at the import:
$ ende check let.ts
Check let.ts
TS2305 [ERROR]: Cannot import "calls" from "file:///Users/me/app/vendor/kit/mod.ts": it is a let or var binding, whose value can change after a snapshot, which can't leave the sandbox of isolate["./vendor/kit/"]. A sandboxed package can only export functions and classes (called async, through handles) and constants. Only its type can be used outside the sandbox.
at file:///Users/me/app/let.ts:1:10
TS1362 [ERROR]: 'calls' cannot be used as a value because it was exported using 'export type'.
console.log(calls);
~~~~~
…
Found 2 errors.
error: Type checking failed.
An Ende.Root the app passes into a
sandbox carries the app's authority for that folder, so a [] sandbox can write
through a write root it is given but not by plain path. A write root over the
project, its code or its config isn't passed into a sandbox.
Sync and lazy calls
Two options change how calls are made. Neither changes what the sandbox may do, and turning either on or off needs no new approval.
"sync": true makes calls into the sandbox block until they return, so they
give values instead of promises:
{
"isolate": {
"./vendor/fast/": { "permissions": [], "sync": true }
}
}import { Counter, shout } from "./vendor/fast/mod.ts";
console.log(shout("hello"));
const counter = new Counter();
counter.increment();
console.log(counter.increment());While a sync call waits, nothing else in the app runs: no timers, servers or signal listeners. A callback the sandbox makes into the app during the call fails. A sandbox that never answers keeps the app waiting; there is no timeout.
"lazy": true starts the sandbox's worker at the first call instead of at the
import, so a package that is imported but never called costs nothing. The
package's top-level code, its output and its load errors come with the first
call. Only functions can be imported from a lazy rule:
$ ende run -A lazyconst.ts
error: Cannot import "FORMAT" from "file:///Users/me/app/vendor/report/mod.ts": it is a constant, and isolate["./vendor/report/"] has "lazy": true, which starts its worker at the first call and so can only give functions. Drop "lazy" from the rule or import only functions from it
What a sandbox can't write
A sandbox granted write still can't change what configures or runs the app.
Whatever its grant:
- It never writes a file named
ende.json,ende.jsonc,deno.json,deno.jsonc,ende.lockordeno.lock, anywhere, nor the import map, the vendor folder or the module cache in use. - Outside its own folder, it never creates or writes a file whose name Ende
could load as code (a
.ts,.js,.json,.wasmor native library name), and never makes a file executable. The check goes by name: what a file holds isn't inspected, so a sandbox can still write a script with another name, or none. - It can't call
Ende.chdir(), which would change the whole process's working directory.
$ ende run -A main.ts
Recorded isolate["./vendor/report/"] in ende.lock; it will run with: write /Users/me/app/out
saved out/report.txt
NotCapable: ./vendor/report/: Requires write access to "./out/evil.js", which is a file Ende could load as code (by its extension), and no sandbox or extension may write code outside its own folder: it could run with the app's permissions on a later run
NotCapable: ./vendor/report/: Requires write access to "./out/../ende.json", which would configure or pin the app (a config file or lockfile Ende looks for, by any spelling), so no sandbox or extension may write it
Ende also refuses a write grant that would let a sandbox change the app's code on a later run: the project folder itself, or any folder that already holds code. Grant a folder of data instead:
$ ende run -A main.ts
error: isolate["./vendor/report/"] may write /Users/me/app/scripts, which holds /Users/me/app/scripts/deploy.ts, a file Ende could load as code (another entry point, a test or a module a later run starts with the app's permissions); grant a folder of data instead
A folder a sandbox may write is untrusted. While the grant is in ende.json,
Ende loads no code from it, and the next run refuses the grant if the folder
holds a file that starts with #! or is executable. Once you remove the grant,
nothing stops Ende loading what the sandbox left there, and other tools that
read or run files in it were never guarded. Check what a sandbox wrote before
you run or move it.
Approving changes
The lockfile pins each rule's grant and the manifests of the packages it
sandboxes. A rule is recorded per entry point, by the first run that imports
it or by ende install --entrypoint with an entry point that imports it. Each
record prints the Recorded … line, which shows even with --quiet. Adding the
rule to ende.json is the approval.
Record new rules before you commit, so that what CI runs was recorded where you could see it:
$ ende install --entrypoint main.ts
Recorded isolate["./vendor/csv/"] in ende.lock; it will run with: no permissions
Plain ende install, and ende install --entrypoint with entry points that
don't reach a rule, records nothing for it and says so:
$ ende install
Warning ende.lock has no record of these isolate rules yet, so `ende ci` fails and the first run that imports them records them:
isolate["./vendor/csv/"]
Run `ende install --entrypoint <entry>` with the entry points that import them (or, for a rule only a computed import() reaches, its sandboxed module), and commit ende.lock. Remove rules nothing imports.
For a rule that only a computed import() reaches, pass the sandboxed module
itself, such as ende install --entrypoint vendor/csv/mod.ts. Remove rules
that nothing imports: until they are recorded, they make ende ci fail.
Two kinds of change stop a run before the sandbox starts: any change to a
rule's grant in ende.json, a narrowing one included, and a run that would give
a sandbox more than any approved run had. The error names the command that
approves it:
$ ende run --allow-read main.ts
error: isolate["./vendor/csv/"] changed since ende.lock approved it: its grant in ende.json. Run `ende install --entrypoint main.ts` to review the change and approve it.
ende install --entrypoint
shows what the run would get and asks, or approves with --yes:
$ ende install --entrypoint main.ts --yes
isolate["./vendor/csv/"] changed:
grant (ende.json):
- []
+ {"read":["./data"]}
new run from main.ts (asks for: no manifest): read /Users/me/app/data
(never more than the app)
Recorded the approved changes to isolate["./vendor/csv/"] in ende.lock.
Plain ende install approves a new grant text, but a run that gets more than
before still needs --entrypoint. Removing a rule needs approval too, since the
package would then run with the app's permissions:
$ ende run -A main.ts
error: isolate["./vendor/csv/"] is no longer declared in ende.json, but ende.lock still pins it and the app imports file:///Users/me/app/vendor/csv/mod.ts, which it sandboxed. Removing the rule would run that package with the app's permissions. Run `ende install` to approve the removal, or declare the rule again
A manifest that only narrows runs without a new approval. Without a terminal,
ende install refuses unless given --yes.
In CI, run ende ci, or freeze the lockfile with
"lock": { "frozen": true } or --frozen. ende ci never approves anything:
its refusal names the ende install command to run locally before you commit
ende.lock. It also fails on a rule ende.lock has no record of. A frozen run
can't record a rule either, and names the command that does:
$ ende run --frozen --allow-read main.ts
error: isolate["./vendor/csv/"] isn't recorded in ende.lock, and the lockfile is frozen (--frozen, or lock.frozen in ende.json), so this run can't record it. Run `ende install --entrypoint main.ts --frozen=false` to record it, or rerun with --frozen=false.
Without either, the first run in CI that imports a new rule records it, unseen.
Warning
Deleting ende.lock drops every approval. The next run records each rule
again as it is now, printing only the Recorded … line.
Remote and jsr: code is pinned by the lockfile's usual integrity hashes. Local
sandbox folders aren't pinned by content: a sandbox can only narrow what the app
may do, and the app could change those files anyway.
Rules need the lockfile. "lock": false is an error while isolate rules are
declared, and --no-lock runs them unpinned with a warning that --quiet
doesn't hide.
To see what each dependency runs with, use
ende grants. Pass it the same permission
flags you pass to ende run.
Nested rules
When a sandboxed package imports a package another rule matches, that package runs in a sandbox nested inside the first: it gets its own grant narrowed by the outer sandbox's, and by the app's. A package the app and a sandbox both import runs in two workers, each narrowed by its importer.
Limits
Per-package permissions are a worker boundary inside one process. They are only as strong as what they cover:
-
Unmatched code keeps the app's full permissions. Only the modules a rule matches, and what those modules import, are sandboxed. Everything else the app imports itself, including dependencies you forgot to name, runs in the app.
-
runandffican escape. A subprocess or native code ignores Ende's permissions.ende grantsflags such grants ascan escape. -
envandsysare process-wide. An environment variable a sandbox sets is seen by the app. Here a sandbox granted{"env": ["MODE"]}setsMODE, the app prints it, and then the sandbox triesEnde.chdir():$ ende run -A main.ts Recorded isolate["./vendor/tool/"] in ende.lock; it will run with: env MODE set by the sandbox NotCapable: ./vendor/tool/: Ende.chdir() changes the working directory of the whole process, so sandboxed code and extensions can't call it -
No CPU or memory isolation. A sandbox can use as much CPU time and memory as it likes, and timing side channels between threads aren't addressed.
-
What you hand over is handed over. A callback or an object of your own that you pass in runs with the app's permissions. Never run code a sandbox returns (a string to
eval, a module, aBlobURL): it would run with the app's permissions. -
Not supported:
ende compileandende desktoprefuse an app withisolaterules;npm:matchers; a main, test or preload module inside a sandbox; importing a sandboxed package from a worker the app starts; getters, setters andlet/varexports.