playground | github | npm | discord
TJS is a language. It's what JavaScript always promised, but never quite delivered. Indeed it's what Apple's Dylan promised and never delivered. Instead of "a lot of the power of Lisp", all the power of Lisp. Instead of C-like Syntax, actual JavaScript syntax. Instead of easy to learn but with weird corner cases, dangerous gotchas, and problems at scale, we fix the corner cases, remove the gotchas, and provide the tools that let you scale.
TJS is also a runtime. A runtime that remembers your function declarations and can check whether parameter types are what they ought to be. It can guarantee safety by default, and speed when it's needed (including inline WASM).
AJS is another language. It's a language for safe evaluation with injected capabilities and a gas limit. It's the language tjs allows you to Eval and use to create a SafeFunction. It also has its own VM and runtime to allow you to build universal endpoints. It's a language that's easy for agents to write and comprehend. It can be converted into an AST and run remotely.
TJS is also a toolchain. It transpiles its own source into JavaScript — the transpiler is written in TypeScript, and running it through its own TS→TJS→JS pipeline yields a bootstrapped transpiler whose output matches the native one exactly (src/use-cases/bootstrap.test.ts). That's a compiler that processes its own source, not (yet) a compiler written in its own language. It transpiles TypeScript into TJS and then into JS. It turns function definitions into runtime contracts, documentation, and simple tests. It uses types both as contracts and examples. It allows inline tests of private module internals that disappear at runtime. It compresses transpilation, linting, testing, and documentation generation into a single fast pass. As for bundling? It allows it but it targets an unbundled web.
TypeScript is fragile. It pretends to be a superset of JavaScript, but it isn't. It pretends to be typesafe, but it isn't. Its Turing-complete type system is harder to reason about than the code it supposedly documents—and then it all disappears at runtime.
TypeScript is also difficult to transpile. Your browser can run entire full virtual machines in JavaScript, but most TypeScript playgrounds either fake transpilation by stripping type declarations or use a server backend to do the real work.
JavaScript is dangerous. eval() and Function() are so powerful they're forbidden almost everywhere—blocked by CSP in most production environments. The industry's answer? The Container Fallacy: shipping a 200MB Linux OS just to run a 1KB function safely. We ship buildings to deliver letters.
Security is a mess. Every layer validates. Gateway validates. Auth validates. Business logic validates. Database validates. We spend 90% of our time building pipelines to move data to code, re-checking it at every hop.
What if your language were:
- Honest — types that actually exist at runtime, not fiction that evaporates
- Safe — a gas-metered VM where infinite loops are impossible, no container required
- Mobile — logic that travels to data, not oceans of data dragged to logic
- Unified — one source of truth, not TypeScript interfaces plus Zod schemas plus JSDoc
That's what TJS Platform provides: TJS for writing your infrastructure, and AJS for shipping logic that runs anywhere.
Write typed JavaScript where the type is an example. No split-brain validation.
// TJS: The type is an example AND a test
function greet(name: 'World'): 'Hello, World!' {
return `Hello, ${name}!`
}
// At transpile time: greet('World') is called and checked against 'Hello, World!'
// Runtime: The type becomes a contract
console.log(greet.__tjs.params) // { name: { type: 'string', example: 'World', required: true } }
// Safety: Errors are values, not crashes
const result = greet(123) // MonadicError: Expected string for 'greet.name', got numberWhy it matters:
- One source of truth — no more TS interfaces + Zod schemas + JSDoc comments
- Types as examples —
name: 'Alice'means "required string, like 'Alice'" - Runtime metadata —
__tjsenables reflection, autocomplete, documentation from live objects - Monadic errors — type failures return values, never throw
- Zero build step — transpiles in the browser, no webpack/Vite/Babel
- The compiler is the client — TJS transpiles itself and TypeScript entirely client-side
Write logic that compiles to JSON and runs in a gas-limited sandbox. Send agents to data instead of shipping data to code.
const agent = ajs`
function research(topic: 'AI') {
let data = httpFetch({ url: '/search?q=' + topic })
let summary = llmPredict({ prompt: 'Summarize: ' + data })
return { topic, summary }
}
`
// Run it safely—no Docker required
const result = await vm.run(
agent,
{ topic: 'Agents' },
{
fuel: 500, // Strict CPU budget
capabilities: { fetch: http }, // Allow ONLY http, block everything else
}
)Why it matters:
- Safe eval — run untrusted code without containers
- Code is JSON — store in databases, diff, version, transmit
- Fuel metering — every operation costs gas, infinite loops impossible
- Capability-based — zero I/O by default, grant only what's needed
- LLM-native — simple enough for small models to generate correctly
The agent carries its own validation. The server grants capabilities. Caching happens automatically because the query is the code.
The holy grail: eval() that's actually safe.
import { Eval } from 'tjs-lang/eval'
// Whitelist-wrapped fetch - untrusted code only reaches your domains
const safeFetch = (url: string) => {
const allowed = ['api.example.com', 'cdn.example.com']
const host = new URL(url).host
if (!allowed.includes(host)) {
return { error: 'Domain not allowed' }
}
return fetch(url)
}
const { result, fuelUsed } = await Eval({
code: `
let data = fetch('https://api.example.com/products')
return data.filter(x => x.price < budget)
`,
context: { budget: 100 },
fuel: 1000,
capabilities: { fetch: safeFetch }, // Only whitelisted domains
})The untrusted code thinks it has fetch, but it only has your fetch. No CSP violations. No infinite loops. No access to anything you didn't explicitly grant.
What the sandbox guarantees, and what it doesn't (as of v0.12.0 — be precise here, because a security claim you can't cash is worse than none):
- Termination is guaranteed, not decided. Fuel metering sidesteps the halting problem rather than solving it: every atom costs fuel and execution stops when it runs out, so a program either finishes or is killed. There is no "will it halt?" question to answer.
- No ambient authority. The VM has zero IO by default; the only way out is a capability you
inject. Every atom touching one is tagged
effects: 'io'and that tagging is itself test-guarded, so the audit surface is enumerable. - The guest holds data, not references. Capability returns cross a
structuredClonemembrane, so a guest can't reach a host object or mutate one you still hold. - Layered and tested — not formally proven. The properties above are structural and could in principle be proven; today they are enforced by construction and covered by an adversarial test suite. Treat "proven" as the roadmap, not the current state.
- Known gap: cross-endpoint amplification. Recursive agent calls are bounded by a depth
header (
X-Agent-Depth, max 10), but that is cooperative — it stops accidental loops and friendly infrastructure, not an adversarial endpoint that simply drops the header. If you expose completely open endpoints, rate-limit them. - Out of scope: timing side channels, JS-engine JIT bugs, and memory-level attacks. A JS-in-JS sandbox cannot address those; put process isolation underneath if your threat model includes them.
npm install tjs-langimport { ajs, AgentVM } from 'tjs-lang'
const agent = ajs`
function double(value: 21) {
return { result: value * 2 }
}
`
const vm = new AgentVM()
const { result } = await vm.run(agent, { value: 21 })
console.log(result) // { result: 42 }import { tjs } from 'tjs-lang'
const { code, metadata } = tjs`
function add(a: 0, b: 0): 0 {
return a + b
}
`
// code: JavaScript with __tjs metadata attached
// metadata: { add: { params: { a: { type: 'number', example: 0 }, b: { type: 'number', example: 0 } }, returns: { type: 'number' } } }Since TJS compiles itself, the playground is the full engine running entirely in your browser.
| TypeScript | TJS | AJS | |
|---|---|---|---|
| Purpose | Write your platform | Write your platform | Write your agents |
| Trust level | Your code | Your code | Anyone's code |
| Compiles to | JavaScript + .d.ts |
JavaScript (with runtime checks + introspection) | JSON AST |
| Runs in | Browser, Node, Bun | Browser, Node, Bun | Sandboxed VM |
| Types | Static only (erased at runtime) | Examples → runtime validation | Schemas for I/O |
| Errors | Exceptions | Monadic (values, not exceptions) | Monadic |
| Build step | tsc → JS + .d.ts |
Runs tests, builds docs, produces JS | None |
Note: TJS can transpile TypeScript into JS (via TJS) using
tjs convert, giving your existing TS code runtime type checks and introspection. You can even add inline tests using/*test ...*/comments that run automatically during the build.
The cost of "safe eval"—compare to a 200MB Docker image. Measured at v0.13.0; each row is a standalone entry point, not an increment (import only what you need):
| Entry point | Bundle | Size | Gzipped |
|---|---|---|---|
tjs-lang/vm (VM only) |
tjs-vm.js | 272 KB | 83 KB |
tjs-lang/batteries |
tjs-batteries.js | 10 KB | 4 KB |
tjs-lang/lang (transpiler) |
tjs-lang.js | 239 KB | 76 KB |
tjs-lang (full, TS support) |
index.js | 326 KB | 104 KB |
These numbers are verified by
src/bundle-size.test.ts, which re-measures the built bundles and fails if this table drifts — so they can go stale by at most one release.
Dependencies: acorn + acorn-walk/acorn-loose (JS parsing), tosijs-schema
(validation). All have zero transitive dependencies.
- TJS Language Guide — Types, syntax, runtime
- AJS Runtime Guide — VM, atoms, capabilities
- WASM Quick Start — Build WASM-accelerated libraries with zero toolchain setup
- Architecture Deep Dive — How it all fits together
- Playground — Try it now
# npm
npm install tjs-lang
# bun
bun add tjs-lang
# pnpm
pnpm add tjs-langApache 2.0