Xript.Runtime
0.3.1
See the version list below for details.
dotnet add package Xript.Runtime --version 0.3.1
NuGet\Install-Package Xript.Runtime -Version 0.3.1
<PackageReference Include="Xript.Runtime" Version="0.3.1" />
<PackageVersion Include="Xript.Runtime" Version="0.3.1" />
<PackageReference Include="Xript.Runtime" />
paket add Xript.Runtime --version 0.3.1
#r "nuget: Xript.Runtime, 0.3.1"
#:package Xript.Runtime@0.3.1
#addin nuget:?package=Xript.Runtime&version=0.3.1
#tool nuget:?package=Xript.Runtime&version=0.3.1
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.1",
"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
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 | Not yet | 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.6.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.