Trine security model (S5; reviewed for 1.0, M10)

What Trine promises about running a program, what backs each promise, and what it doesn't promise. The intended reader runs code they didn't write: a dependency, a script from the internet, or a program an AI agent produced.

Who we defend against

partytrusted?
the person running trineyes: they choose the grants
the Trine program being run, its modules and its packagesno
the input the program readsno
the machine: OS, C compiler, the trine binary itself, the project folderyes

Someone who can write to your project folder or your trine binary can already run code as you; that is out of scope (see "The run cache" below).

Guarantees

1. Memory safety: no undefined behaviour from Trine code

A Trine program can't read or write memory it doesn't own, in any engine.

What backs it: the compiler and VM are Rust with **zero unsafe blocks** (S1). The native runtime (runtime/trine_rt.h) and generated code are C, which Rust can't vouch for; that part is covered by testing rather than by construction:

So the guarantee for native code is "no known violation, under heavy differential and sanitized fuzzing", not a proof.

2. No access to the outside world without a grant

A program can touch files, the environment, standard input and its arguments only through capabilities (#21, CAPABILITIES.md):

The rest of the outside world arrived (M2-M8) as more capabilities and grants, each refused without its flag:

reachneedsnotes
clock, seedsSys (now, seed)no grant; deterministic replay records them
other programs--allow-runrun, run_input: any program on the PATH, so this grant is everything the user can do
network--allow-net[=HOSTS]http, tcp_connect (through Sys or a Net) only to the hosts named; redirects aren't followed (the status and location say where)
Python--allow-pythonpython(dir, file), py_start(sys): Python has the user's full authority; the grant trusts whatever Python code runs
C--allow-c (pure math excepted)extern fn: C has full authority and can break memory safety; calls passing pointers must sit in unsafe: blocks (FFI.md), so they are few and visible, and buffers are guard-checked

trine caps marks every function that reaches Python or C as UNCHECKED: what it can do isn't bounded by its type.

3. Deterministic programs

Without input, a Trine program's output is a function of its source: no clock or randomness without Sys, no hash-order iteration (maps and sets keep insertion order), and no data races: tasks (spawn, async fn) share only immutable values and hold no capability but a Net or a connection they own (the isolation checker, PARALLEL.md), and their output and errors come in program order. This is what lets trine run replay a program natively mid-run, and it makes agent-written programs reproducible.

4. Resource limits (S4)

trine run p.tr --max-steps=1000000 --max-time=5 --max-mem=256M --max-output=1M
flagstops the program whennotes
--max-steps=Nmore than N steps: a step is one call of a function you wrote or a lambda, or one loop iteration (each loop test, the last one included)identical in all three engines (tested), so a program stops at the same point everywhere: deterministic, unlike time. Loops inside scheduled kernels (.sched) aren't counted. Native builds count only when built for it (a separate cached build; a plain trine build executable refuses the flag instead of ignoring it), because counting costs speed (fib: 7 → 55 ms)
--max-time=SS seconds of wall-clock timeall engines; output already written stays
--max-mem=SIZEthe heap would grow past SIZE (64M, 1G)native code (address-space cap)
--max-output=SIZEprinting a line would exceed SIZE bytesthe line that doesn't fit isn't printed

Each limit ends the run with a runtime error naming the flag (step limit reached (--max-steps=1000)), exit status 1, code limit in --json.

5. Hostile source code doesn't hurt the compiler

Deeply nested or enormous programs fail fast with an error (S2: nesting ≤ 256, operator chains ≤ 10,000), the type checker has no known super-linear blowups on them, and the lexer, parser, checker and VM are fuzzed for panics and hangs (S3). Generated C escapes every string byte in octal, so no Trine string can inject C code. Constants are computed at compile time with a budget (10 million steps, about a second): a constant written to loop forever is a compile error, not a hung compiler or editor (found in the 1.0 review). Checking a program never runs it otherwise: no build scripts, no macros, no code from packages at compile time.

Not guaranteed (today)

gapconsequenceplan
Limits are opt-inwithout flags, an infinite loop runs forever and an allocation loop runs until the OS stops itpass the limits below when running code you don't trust
**--max-mem is native-only and approximate**it caps the process's address space (Linux); the interpreter can't cap its own memory, so --interp/--vm refuse the flag and plain trine run compiles firstan allocator-level cap if needed
Standard output is ungatedany program can printintended: output is how programs answer; --max-output caps its size
Resolve-then-open racea different process that can modify a granted directory tree can swap a directory for a link between Trine's path check and the open, redirecting one operationuse openat2(RESOLVE_BENEATH) on Linux; Trine programs themselves can't race (tasks can't hold a Dir)
Type-checker blowup on purposeHindley-Milner types can grow exponentially in contrived programs (let b = (a, a) repeated); checking such a file is slow or runs out of memoryas in every ML-family language; run trine check on untrusted code with OS limits
Fetching a project's git dependencieschecking a project fetches the git URLs its trine.toml names (no code runs; only files are downloaded, then hashed against trine.lock). URLs, revs and lock entries are checked first (below), but git itself still talks to whatever server the URL namesuse --locked for projects you don't trust, so nothing new is fetched
The shared build cachenative builds are reused across projects from $TRINE_HOME/build, keyed by the C source and compiler; anyone who can write there can replace an executablesame trust as your home directory; TRINE_NO_BUILD_CACHE=1
No cryptographic randomnessrandom/random_below are SplitMix64: anyone who sees a few outputs can predict the rest. seed(sys) reads the OS (/dev/urandom, rand_s on Windows) but falls back to the clock and process id when that fails, silently; the interpreter on Windows always falls back (it reads /dev/urandom)never use them for tokens, passwords or keys: use run(sys, ["openssl", "rand", "-hex", "32"]) or Python's secrets (PYTHON.md). After 1.0: a secure_random(sys) that fails instead of falling back
Side channelstiming and memory use reveal information about secretsout of scope
The C compilernative builds trust the system ccout of scope (same as any compiled language)
Proofs for native codememory safety of generated C rests on fuzzing and sanitizers, not on a proofthe verifier's facts are re-checked in debug builds; a verified backend is far off

Cryptography and quantum computers

Trine uses no public-key cryptography, which is the part large quantum computers would break (RSA and elliptic curves, through Shor's algorithm). What it does use:

usealgorithmquantum view
definition hashes, trine.lock content hashes, build cache keys, trine migrate proofsSHA-256 (src/hash.rs, no dependencies)safe: Grover's algorithm halves preimage strength to about 128 bits, still out of reach; collisions stay harder than that in practice
pinning git dependenciesgit commit ids (SHA-1, or SHA-256 in SHA-256 repositories)SHA-1 is weak today for classical reasons, not quantum ones; Trine also pins a SHA-256 hash of the files, so a forged commit with different files is refused
https:// in httpthe system's curlwhatever curl's TLS library negotiates; OpenSSL 3.5 and later already use a hybrid post-quantum key exchange (X25519MLKEM768) by default. Trine holds no keys
plain tcp_connectnoneunencrypted, as documented

The one place this will matter is signed releases: prebuilt binaries (P8) ship with SHA-256 checksums, which stay safe, and signed build attestations (Sigstore, through GitHub), which use elliptic curves like every signature made today. The plan is to add post-quantum signatures (ML-DSA, FIPS 204) when the signing tools support them, rather than writing our own.

The run cache

trine run keeps native builds in .trine/bin/ keyed by a hash of the program and the compiler, and runs a cached executable without recompiling. Anyone who can write to .trine/ can replace that executable; that's the same trust as the project folder itself (an attacker who can write there can also edit the source). The cache never crosses projects, and TRINE_NO_CACHE=1 disables it. Since M3, native builds are also kept in a cache shared by every project of the same user ($TRINE_HOME/build, PACKAGES.md), with the same trust.

The 1.0 review (M10)

For 1.0 every boundary was walked again with the attacks below; each is a case in the test sandbox_escapes_are_refused (interpreter and native code) unless named otherwise.

boundarytriedresult
a granted directory../secret, an absolute path, a symlink to a file outside, a symlinked directory leading outsiderefused (outside the directory); nothing read
read-only grantswriting into a directory granted with --allow-readrefused; the file unchanged
ungranted directories, environment, programs, Pythondir(sys, "."), env, run, py_start without their flagsrefused with the flag to pass
network hostshttp and tcp_connect (through net(sys)) to a host not grantedrefused before connecting
forging authoritycalling a capability builtin with something that isn't a capabilitya type error (expected Sys)
tasksa task capturing sysa type error (the isolation checker)
Ca pointer-passing extern outside unsafe:; any C call without --allow-ca type error; a runtime refusal
the compilera constant that never finisheswas a hang; now a compile error within a second
packagesa git dependency whose files don't match trine.lockrefused (two_package_project_builds_reproducibly_from_a_clean_checkout)
buffers given to Ca C function writing past the enda runtime error, every engine (zlib_through_c_strings_buffers_and_unsafe_blocks)

The second review: outside input (after 1.0)

AI-driven attack tools find known kinds of weakness quickly, so everything that reaches Trine from outside a program was read again with them in mind: project files, the network, other programs, the C runtime. The attacks are the test hostile_inputs_are_refused_the_same_everywhere unless named otherwise.

boundaryfoundnow
trine.lock (comes with a project)a commit like /../../x went into a temporary folder name: git wrote a checkout outside the package cache (Linux, confirmed), and on Windows the delete before it could remove a folder such as AppDataan entry must be a 40 or 64 digit hex commit id and a sha256: hash of 64 hex digits, or the lock is "damaged"
trine.toml git URLs and revsa URL starting with - was read by git clone as an option (no command ran, but only because the next argument wasn't a repository); ext:: URLs relied on git's own default to stay offURLs: https, http, ssh, git, file, user@host:path or a local path, never -... or x::...; -- before every URL; protocol.ext and protocol.fd forced off; revs can't start with -
run, http and Python on Windows (native)CreateProcess searches the current directory before the PATH: a curl.exe or python3.exe planted in a project folder would run for a program granted only --allow-netprograms are found on the PATH only, as Rust (the interpreter) does; not yet run on Windows
batch files on Windows (native)a granted .bat runs under cmd.exe, which re-reads &, `\, %VAR%` in its argumentsonly plain arguments (letters, digits, _-.,/:=+@\) reach a batch file; not yet run on Windows
https:// through curlcurl read ~/.curlrc (which can turn on following redirects to ungranted hosts) and expanded {a,b} / [1-100] in URLs (one call, many requests)curl -q -g --proto =https
HTTP header namesany name without : or spaces; @file names are curl's syntax for reading a file of headersnames are RFC 9110 tokens; values can't hold CR, LF or NUL
HTTP responsessix kinds of malformed response gave different answers on the interpreter and native code (lone \r or \n in the head, signs in numbers, repeated Content-Length, Unicode spaces, chunk extensions)one rule on every engine: lines end with CRLF only, numbers are plain digits, a repeated length is no length
HTTP requests (native)the request line was built in a 700-byte buffer: longer URLs were cut short (safe, but a broken request)any length
the C runtime's HTTP parser4,800 fuzzed hostile responses (a server sending mutations of valid responses) against native code under AddressSanitizer and UBSanno memory errors or undefined behaviour

Not yet done: a reading of this model and its code by someone other than its authors. Until that happens, the claims above are tested, not independently audited.

Running untrusted code: a checklist

  1. Run trine caps program.tr and read what each function can reach.
  2. Grant the least you can: a read-only directory (--allow-read=data), named environment variables only (--allow-env=HOME).
  3. Set limits: --max-steps (deterministic) or --max-time, plus --max-mem and --max-output.
  4. Prefer the interpreter for one-off untrusted runs (trine run --interp): it involves no C compiler and no cached executables.

Reporting

Security bugs: a Trine program that reads or writes memory it shouldn't, escapes a granted directory, reaches the environment without a grant, crashes the compiler, or makes two engines disagree. Each gets a regression test in tests/ and, where it applies, a fuzzer case.