Overview
Deno is a JavaScript, TypeScript, and WebAssembly runtime with secure defaults and a great developer experience. The runtime is built on three core technologies:- V8: Google’s JavaScript and WebAssembly engine
- Rust: Systems programming language for the runtime implementation
- Tokio: Asynchronous runtime for Rust
Architecture Components
V8 JavaScript Engine
At its core, Deno uses V8, the same JavaScript engine that powers Chrome and Node.js. V8 compiles JavaScript to native machine code for fast execution and provides:- Just-in-time (JIT) compilation
- Optimized garbage collection
- WebAssembly support
- Modern JavaScript features (ES2023+)
Rust Runtime Layer
The Deno runtime is implemented in Rust, providing:- Memory safety without garbage collection
- Zero-cost abstractions
- Secure defaults through explicit permissions
- Native performance for system operations
Tokio Async Runtime
Deno uses Tokio for asynchronous I/O operations:- Multi-threaded task scheduler
- Async filesystem operations
- Network I/O
- Timer management
The combination of V8’s JavaScript execution, Rust’s safety guarantees, and Tokio’s async capabilities creates a runtime that is both fast and secure.
Runtime Structure
MainWorker
The main API of thedeno_runtime crate is MainWorker, which:
- Encapsulates
deno_core::JsRuntime - Implements the
Denonamespace - Manages the module loading pipeline
- Handles permissions checking
Example: Running Code
deno run --allow-net server.ts, the runtime:
- Parses the TypeScript code
- Type checks (if enabled)
- Compiles TypeScript to JavaScript
- Loads the module into V8
- Executes with the granted permissions
Web Workers
Deno supports the Worker Web API throughWebWorker structures:
- Each worker spawns a dedicated OS thread
- Workers are descendants of
MainWorker - Communication happens via message passing
- Workers inherit or restrict parent permissions
Extensions System
Deno’s functionality is organized into extensions located in theext/ directory:
- ext/web: Web APIs (fetch, streams, events)
- ext/net: Network operations
- ext/fs: Filesystem operations
- ext/http: HTTP server
- ext/crypto: Web Crypto API
- ext/node: Node.js compatibility
- Ops: Rust functions exposed to JavaScript
- JavaScript APIs: High-level interfaces
- Type definitions: TypeScript declarations
Extensions provide native functionality to JavaScript through a secure “ops” system, where each operation can be permission-checked before execution.
Module Loading
The module loader handles ES modules, TypeScript, and various module formats:Module Resolution
Deno resolves modules in this order:- File protocol: Local filesystem (
file://) - HTTP(S): Remote modules (
https://) - npm: npm packages (
npm:package@version) - jsr: JSR packages (
jsr:@scope/package) - node: Node.js built-ins (
node:fs)
Performance Optimizations
Code Caching
Deno caches compiled code to improve startup performance:- V8 code cache for JavaScript modules
- Incremental compilation for TypeScript
- Cache invalidation based on file modification time
Fast Ops
The ops system provides zero-copy operations between Rust and JavaScript:Security Model
The runtime enforces security at multiple levels:- Permission checks before any privileged operation
- Sandboxed V8 execution without host access by default
- Explicit grants required for filesystem, network, environment
Next Steps
Learn about Deno’s permission system to understand how security is enforced at runtime.