Getting Started
Build Velyr from source, run your first script, and grant it your first permission.
Velyr is a security-first JavaScript and TypeScript runtime written in Rust. Scripts start with no access to files, network, environment or processes, and you grant what they need.
Install a prebuilt binary#
Each GitHub release publishes velyr-<target>.tar.gz (.zip on Windows) archives and a SHA256SUMS file. Targets:
- Linux:
x86_64andaarch64, withgnuandmuslvariants. - macOS:
x86_64-apple-darwinandaarch64-apple-darwin. - Windows:
x86_64-pc-windows-msvc.
Download the archive for your platform, verify it against SHA256SUMS, extract it and put velyr on your PATH.
Build from source#
You need git and rustup. The repository pins its Rust toolchain in rust-toolchain.toml, and rustup installs it on first build. The build downloads a prebuilt V8 and compiles a large dependency tree, so the first build takes a while.
-
Clone the repository.
bash git clone https://github.com/velyrlabs/velyr.git cd velyr -
Build the CLI in release mode.
bash cargo build --release -p velyr-cli -
The binary is
target/release/velyr. Check it.bash ./target/release/velyr --versionIt prints
velyr 0.1.0-alpha.1.
Put target/release on your PATH, or copy the binary somewhere that is. The examples below assume velyr is on your PATH.
Run your first script#
Create hello.js:
const greeting = new TextEncoder().encode("hello from velyr");
console.log(new TextDecoder().decode(greeting));
await new Promise((resolve) => setTimeout(resolve, 100));
console.log("done");Run it:
velyr run hello.js.js and .mjs files run as ES modules, so import, export and top-level await work. Nothing in this script needs a permission.
Grant a permission#
Try reading a file:
try {
console.log(await Velyr.readTextFile("./notes.txt"));
} catch (error) {
console.log(error.code);
}Without a grant, the read fails:
echo "remember this" > notes.txt
velyr run read.jsVELYR_PERMISSION_DENIEDGrant read access to the current directory. Note the =: values are attached to the flag.
velyr run --allow-read=. read.jsremember thisGrants are scoped. --allow-read=./data allows only that directory and what is inside it, and --deny-read=./data/secrets carves out an exception that always wins. You can also put the same settings in a velyr.json file. The full rules are in Permissions.
What next#
- Why Velyr explains the principles and the trade-offs.
- Features lists what exists today and its status.
- Command Line Interface documents
velyr run, its flags and exit codes. - Permissions covers every permission kind and how denials look.
- Modules, Web APIs and Workers cover the runtime itself.
- Error Codes lists every
VELYR_*code.