Skip to content

Sandbox and limits

Restrict an Elide program's filesystem, network, subprocess, thread and native access with --sandbox and --allow-* flags, and limit resources and run time.

On this page

Programs run unrestricted until you pass a sandbox flag. --sandbox denies filesystem access; network and subprocesses stay allowed until you list hosts or commands:

Terminal
bash
elide --sandbox --allow-read=. --allow-net=example.com run app.js
elide --sandbox — filesystem, network and subprocess policy
 ~/demo  elide [...]
[elide.fs] allow read fs /home/demo/demo
[elide.fs] allow read fs /home/demo/demo/app.mjs
[elide.fs] allow read fs /home/demo/demo/app.mjs
[elide.fs] DENY  read stat ./data/config.json
[elide.fs] DENY  read open ./data/config.json
read : EACCES: permission denied, open './data/config.json'
fetch: fetch to 'example.com:443' is not permitted; grant it with --allow-net=example.com
spawn: spawn of 'uname' is not permitted; grant it with --allow-run=uname
 ~/demo  elide [...]
read : { "region": "eu-west-1", "replicas": 3 }
fetch: fetch to 'example.com:443' is not permitted; grant it with --allow-net=example.com
spawn: spawn of 'uname' is not permitted; grant it with --allow-run=uname
 

Allow file access

Terminal
bash
elide --allow-read=. --fs-audit run app.js
text
[elide.fs] allow read open hello.txt
[elide.fs] DENY  write open out.txt
utf-8 · text · Lines: 2

A denied access fails like a protected file: EACCES: permission denied, open 'hello.txt'. Relative paths resolve from the working directory.

WASI programs cannot access host directories until you map one with WasiMapDirs; see WebAssembly. These grants apply to mapped directories, and a WASI open needs both read and write access.

Allow network and subprocesses

Terminal
bash
elide --allow-net=localhost --allow-run=ls run app.js

A denied call names the grant it needs:

text
TypeError: fetch to 'example.com:443' is not permitted; grant it with --allow-net=example.com
Error: spawn of 'echo' is not permitted; grant it with --allow-run=echo
utf-8 · text · Lines: 2

A --deny-* match reports denied by --deny-net or denied by --deny-run. Policy checks the command that runs, so a shell invocation is checked as sh. Spawn with execFileSync from node:child_process.

Threads and native access

ProgramThreads by defaultNative access by default
JavaScript, TypeScriptNot applicable: node:worker_threads workers run under every flagAllowed
Python entryAllowedAllowed
Python entry with --sandbox or an --allow-read/--allow-write grantDenied; add --allow-threadsAllowed
Python under --interopDenied, even with --allow-threadsAllowed
python
# threads.py
import threading
out = []
t = threading.Thread(target=lambda: out.append("worker ran"))
t.start(); t.join()
print(out[0])
utf-8 · python · Lines: 6
Terminal
bash
elide python threads.py                                         # worker ran
elide --sandbox --allow-read=. python threads.py                # Creating threads is not allowed.
elide --sandbox --allow-read=. --allow-threads python threads.py  # worker ran

--no-native denies native access. Python then lacks some features, such as AF_UNIX sockets (AttributeError: module 'socket' has no attribute 'AF_UNIX') and arbitrary signals, and starts more slowly. --allow-native states the default explicitly; combining it with --no-native is a usage error (exit 2).

Set limits

--limit applies to JavaScript and TypeScript programs. A value is a number, 0 to forbid, or unlimited, the default. Other names, languages or commands are usage errors.

Terminal
bash
elide --limit=workers=4 --limit=fds=128 --max-mem=512m --timeout=30s run app.js

Workers inherit their parent’s grants. These flags do not isolate the process from a native crash.

Pick a profile

--sandbox=trusted is the default profile. --sandbox=sandboxed and --sandbox=isolated are unavailable and exit with code 2.

Flags

FlagEffect
--sandboxDeny filesystem access. Network and subprocesses stay allowed.
--allow-read[=PATHS]Allow reads everywhere, or at the listed paths. Implies --sandbox.
--allow-write[=PATHS]Allow writes everywhere, or at the listed paths. Implies --sandbox.
--fs-auditLog each filesystem decision to stderr.
--allow-net[=HOSTS]Allow all network access, or only the listed hosts (HOST or HOST:PORT).
--allow-run[=CMDS]Allow all subprocesses, or only the listed commands.
--deny-net=HOSTSDeny hosts even when allowed.
--deny-run=CMDSDeny commands even when allowed.
--allow-env[=NAMES]Let elide.pkl read more environment variables, or all of them. process.env is unchanged.
--allow-threadsAllow Python threads in a sandbox.
--allow-nativeAllow native access (the default).
--no-nativeDeny native access.
--limit=workers=NLimit live workers; exceeding it throws ERR_WORKER_LIMIT.
--limit=fds=NLimit open node:fs handles; exceeding it throws EMFILE.
--max-mem=SIZELimit the heap size; exceeding it is an out-of-memory error with a nonzero exit.
--timeout=DURATIONStop the program after DURATION with exit 124.

Lists are comma-separated. --deny-net and --deny-run need the = form.

Samples

Was this page helpful?