Xript.Runtime
0.7.0
See the version list below for details.
dotnet add package Xript.Runtime --version 0.7.0
NuGet\Install-Package Xript.Runtime -Version 0.7.0
<PackageReference Include="Xript.Runtime" Version="0.7.0" />
<PackageVersion Include="Xript.Runtime" Version="0.7.0" />
<PackageReference Include="Xript.Runtime" />
paket add Xript.Runtime --version 0.7.0
#r "nuget: Xript.Runtime, 0.7.0"
#:package Xript.Runtime@0.7.0
#addin nuget:?package=Xript.Runtime&version=0.7.0
#tool nuget:?package=Xript.Runtime&version=0.7.0
Xript.Runtime
C# runtime for xript: sandboxed JavaScript execution via Jint, a pure C# JavaScript interpreter. No native dependencies.
Install
dotnet add package Xript.Runtime
Usage
using System.Text.Json;
using Xript.Runtime;
var manifest = """
{
"xript": "0.7",
"name": "my-app",
"bindings": {
"greet": {
"description": "Returns a greeting.",
"params": [{ "name": "name", "type": "string" }],
"returns": "string"
}
}
}
""";
var bindings = new HostBindings();
bindings.AddFunction("greet", args =>
{
var name = args.Length > 0 ? args[0].GetString() : "World";
return JsonSerializer.SerializeToElement($"Hello, {name}!");
});
using var runtime = XriptRuntime.Create(manifest, new RuntimeOptions
{
HostBindings = bindings,
Capabilities = [],
Console = new ConsoleHandler
{
Log = msg => Console.WriteLine(msg),
Warn = msg => Console.WriteLine($"WARN: {msg}"),
Error = msg => Console.Error.WriteLine(msg),
},
});
var result = runtime.Execute("greet(\"World\")");
// result.Value => "Hello, World!"
// result.DurationMs => 0.1 (approx)
What it does
- Runs user-provided JavaScript inside a Jint sandbox (pure C#, no native interop)
- Only functions declared in the manifest are available to scripts; everything else is blocked
- Supports capability-gated bindings, namespace bindings, hooks, and resource limits
- Fragment processing with
data-bindanddata-ifsupport - Mod loading via
LoadMod()with cross-validation against the host manifest - No
eval, noFunction, no access to the host environment
v0.5.0
- cooperative cancellation via a
CancellationTokenonRuntimeOptions; it interrupts in-flight execution and surfaces a distinct cancellation error (not a timeout), with Jint interrupting mid-run via its token - opt-in capability audit channel: a hook reporting every allowed host-binding invocation as
{ binding, capability, at } - console severity:
ConsoleHandlergained a severity enum (log/info/warn/error/debug) plus a trace channel - sandbox hard caps: host ceilings on memory, CPU time, and stack depth
- manifest
extendswith deep-merge so a manifest can inherit and override host bindings; mod manifests gained an optionalfamilyfield for grouping - host-invoke exports: mods declare named exports the host calls by name and whose return value it honors
- ES module mods via
entry.format: "module", which evaluates the entry as a real ES module through Jint's module API; top-level named exports auto-register as host-invokable, and external imports stay denied - provider-role resolution: mods declare
contributions.providesand the host callsResolveRole(role)(first-installed-wins, settings-overridable) to bind a logical role to a concrete export - slot runtime resolver: ordering by priority, single/multiple cardinality, and capability enforcement on contributions
- DAP-shaped debug protocol: set/clear breakpoints by source position, pause/resume/step in/over/out, and inspect scopes, locals, and stack frames (Jint pauses synchronously on the engine thread)
API
XriptRuntime.Create(manifestJson, options?) -> XriptRuntime
Creates a sandboxed runtime from a JSON manifest string. Validates the manifest on creation.
XriptRuntime.CreateFromFile(path, options?) -> XriptRuntime
Reads a manifest JSON file from disk and creates a runtime.
XriptRuntime.CreateFromValue(doc, options?) -> XriptRuntime
Creates a runtime from a JsonDocument.
runtime.Execute(code) -> ExecutionResult
Executes JavaScript code in the sandbox. Returns ExecutionResult { Value, DurationMs }.
runtime.FireHook(name, options?) -> JsonElement[]
Fires a hook by name, calling all registered handlers. Returns an array of handler return values.
runtime.LoadMod(modManifestJson, fragmentSources?) -> ModInstance
Loads a mod manifest, cross-validates it against the host manifest, and returns a ModInstance with fragment sources.
runtime.Dispose()
Releases sandbox resources. XriptRuntime implements IDisposable, so using works.
When to use this vs other runtimes
Xript.Runtime |
xript-runtime (Rust) |
@xriptjs/runtime |
@xriptjs/runtime-node |
|
|---|---|---|---|---|
| Language | C# | Rust | JavaScript/TypeScript | JavaScript/TypeScript |
| Runs in browser | No | No | Yes | No |
| Sandbox mechanism | Jint (pure C#) | QuickJS (native) | QuickJS WASM | Node.js vm module |
| Best for | .NET apps, Unity, game engines | Rust apps, native tools | Cross-platform, browser, edge | Node.js servers, CLI tools |
| Async bindings | Not yet | Native (rquickjs) | Via asyncify WASM | Native async/await |
Use this package when your host application is .NET. Use xript-runtime for Rust hosts. Use @xriptjs/runtime for JavaScript environments that need universal portability. Use @xriptjs/runtime-node for Node.js-only applications.
Documentation
xript.dev: full docs, getting started guide, and live demos.
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Jint (>= 4.9.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.