Titan Planet Logo
Knowledge

07. Extension System

Extend TitanPL with JavaScript, WebAssembly, Native Rust, Go, or C++ modules for limitless performance and runtime capability.

TitanPL extensions allow developers to extend the Gravity runtime using JavaScript, Rust, Go, WebAssembly, and native system libraries.

Extensions integrate directly into the Gravity runtime and become accessible globally through the t namespace or via explicit imports from that npm package.

TitanPL supports multiple extension architectures optimized for different workloads, ranging from fully sandboxed JavaScript modules to high-performance native runtime integrations.


๐Ÿš€ Extension Types

TitanPL currently supports four extension categories:

TypeRuntimePerformanceSandboxBuild Step
JavaScriptV8StandardFully SandboxedNo
WASMWebAssemblyHighSandboxed (Experimental)Yes
NativeRust/C++MaximumRestrictedYes
GolangGo Shared ObjectHighRestrictedYes

JavaScript Extensions

JS-Only Runtime Extensions

JavaScript extensions run directly inside the Gravity V8 runtime.

They are the simplest extension type and require no native compilation.

Best For

  • Utility libraries
  • Runtime helpers
  • Shared business logic
  • Middleware systems
  • Lightweight runtime APIs
  • Rapid prototyping

Security

JavaScript extensions are fully sandboxed inside Gravity and are always allowed by default.

Create Extension

titan create ext my-ext

Then select: js


Generated Structure

my-ext/
โ”œโ”€โ”€ index.js
โ”œโ”€โ”€ titan.json
โ””โ”€โ”€ utils/
    โ””โ”€โ”€ registerExtension.js

Files

FilePurpose
index.jsMain extension entrypoint
titan.jsonExtension metadata and runtime manifest
registerExtension.jsSafe runtime registration helper

Runtime Registration

JavaScript extensions register themselves onto the global t namespace.

Example:

import { registerExtension } from "./utils/registerExtension.js";


registerExtension("mathx", {
  add(a, b) {
    return a + b;
  }
});

Usage:

import Mathx from 'mathx'

const mathx = new Mathx

mathx.add(5, 2);

Official JS Template


WebAssembly Extensions (Experimental)

WASM Runtime Extensions

WASM extensions allow Rust logic to run inside a portable sandboxed execution environment.

TitanPL compiles Rust WASM modules into runtime-loadable .wasm artifacts.

Best For

  • Parsers
  • Compression systems
  • Cryptography
  • Data processing
  • Portable high-performance logic
  • CPU-heavy algorithms

Security

WASM runs sandboxed and requires explicit permission inside tanfig.json.

Create Extension

titan create ext my-ext

Then select: wasm


Build WASM Extension

titan build ext

Requires:

  • Rust toolchain
  • wasm32-unknown-unknown target

Runtime Output

build/
โ””โ”€โ”€ my-ext.wasm

Allow WASM Permissions inside tanfig.json

{
  "extensions": {
    "allowWasm": true
  }
}

WASM Runtime Notes

  • Runs isolated from native memory
  • Portable across operating systems
  • Lower risk than native libraries
  • Automatically loaded by Gravity

Native Extensions

Native Rust/C++ Extensions

Native extensions provide direct access to operating system APIs and maximum runtime performance.

TitanPL supports Rust native libraries and C++ runtime modules.

Best For

  • Database drivers
  • GPU acceleration
  • Networking engines
  • File system APIs
  • Native protocol bindings
  • Hardware integrations
  • Runtime accelerators

Security

Native extensions are blocked by default.

TitanPL enforces explicit allow-list security through tanfig.json.


Create Native Extension

titan create ext my-native-ext

Then select: native


Build Native Extension

titan build ext

Outputs:

PlatformOutput
Windows.dll
Linux.so
macOS.dylib

Native Permissions

{
  "extensions": {
    "allowNative": [
      "@titanpl/core",
      "my-native-ext"
    ]
  }
}

Gravity Security Policy: TitanPL will trigger a HARD ERROR and refuse to start if any native extension is detected that is not explicitly allowed inside tanfig.json.


Gravity Runtime Architecture

TitanPL executes native extensions outside the primary V8 isolate boundary for runtime stability and crash isolation.

Features

  • Native binary verification

  • Isolated execution layer

  • Runtime permission enforcement

  • Crash isolation

  • Extension manifest validation

  • Learn more about security


Official Native Rust Template


Golang Extensions

Go Shared Library Extensions

TitanPL supports Go shared-object extensions through runtime-loadable binaries.

Best For

  • Existing Go ecosystems
  • Networking tools
  • Concurrency-heavy systems
  • Performance utilities
  • Distributed tooling

Create Extension

titan create ext my-go-ext

Then select: golang


Build Go Extension

titan build ext

Produces:

.dll / .so / .dylib

depending on the target platform.


Official Golang Template


Extension Commands

TitanPL includes a complete extension lifecycle toolkit directly inside the CLI.


titan create ext <name>

Scaffolds a new TitanPL extension package.

Supported Extension Types

TypeDescription
jsPure JavaScript runtime extension
nativeRust native extension
golangGo shared library extension
wasmWebAssembly extension

Generated Structure

native/      โ†’ Native source code
sandbox/     โ†’ Extension testing runtime
titan.json   โ†’ Extension manifest
index.js     โ†’ Runtime registration entrypoint

Example

titan create ext my-ext

titan build ext

Compiles extension runtime binaries.

Supported Targets

  • Rust native libraries
  • Go shared objects
  • WebAssembly modules

Outputs

  • .dll
  • .so
  • .dylib
  • .wasm

Example

titan build ext

titan run ext

Launches the Titan Extension Test Harness.

Features

  • Minimal TitanPL server
  • Isolated Gravity sandbox
  • Native extension injection
  • Runtime validation
  • Local extension linking
  • Temporary virtual TitanPl project
  • Standalone runtime execution

Sandbox Modes

ModeDescription
TitanPL SandboxMinimal TitanPL server
TGRV SandboxStandalone Gravity runtime

Example

titan run ext

Security Configuration

tanfig.json

TitanPL uses explicit runtime permissions for all non-JavaScript extensions.

Example:

{
  "name": "my-secure-app",
  "extensions": {
    "allowWasm": true,
    "allowNative": [
      "@titanpl/core",
      "my-custom-native-ext"
    ]
  }
}

Using Extensions


Typed Import Access

import { log, defineAction } from "@titanpl/native";
import "@titanpl/node/globals";
import bcrypt from "bcryptjs";
import Extension from "ext-template";

const demo = new Extension();

export default defineAction((req) => {
  log(demo.hash("hello"));
})

Extension Runtime Flow

Create Extension
      โ†“
Build Extension
      โ†“
Security Validation
      โ†“
Runtime Registration
      โ†“
Loaded into Gravity
      โ†“
Accessible through t.* or JS import

Recommended Extension Strategy

Use CaseRecommended Type
UtilitiesJS
High-performance portable logicWASM
OS APIs / DriversNative
Existing Go ecosystemGolang

Summary

  • TitanPL supports JS, WASM, Native Rust/C++, and Golang extensions.
  • Extensions integrate directly into the Gravity runtime.
  • Use titan create ext to scaffold new extensions.
  • Use titan build ext to compile runtime binaries.
  • Use titan run ext to test extensions inside isolated sandboxes.
  • WASM and Native extensions require explicit runtime permissions.
  • Extensions become globally accessible through the t namespace or JS import.

On this page