Skip to main content
Experimental Feature - WASM Policy EngineThis SDK is specifically for writing WASM policies using Chainloop’s experimental WASM policy engine. The WASM policy engine is NOT the default policy engine in Chainloop.
  • Default engine: Rego-based (recommended for most users)
  • WASM engine: Experimental alternative for Go/JavaScript policies
  • Status: Experimental preview - APIs may change in future releases
For the default Rego-based policy engine, see Writing Custom Policies.

Prerequisites

The Chainloop JavaScript SDK for WASM policies is built on top of the Extism JavaScript PDK, which enables JavaScript code to run inside WebAssembly with QuickJS. Required tools:
For package management and building.
Compiles JavaScript to WebAssembly.
Dependencies:
  • @chainloop-dev/policy-sdk - Chainloop WASM Policy SDK (npm package)
  • @extism/js-pdk - Extism JavaScript PDK (auto-installed)
  • esbuild - JavaScript bundler (dev dependency)
The Extism JS PDK handles JavaScript-to-WASM compilation using QuickJS, while Chainloop’s WASM Policy SDK provides policy-specific APIs for material validation.

Project Setup

Install Dependencies

Configure Build

esbuild.js:
package.json:
policy.d.ts:
policy.yaml:

Complete Example

API Quick Reference

The JavaScript SDK provides functions for:
  • Execution: run() - Entry point wrapper
  • Material Extraction: getMaterialJSON(), getMaterialString(), getMaterialBytes()
  • Arguments: getArgs(), getArgString(), getArgStringDefault()
  • Results: success(), fail(), skip(), outputResult(), addViolation(), hasViolations()
  • Logging: logInfo(), logDebug(), logWarn(), logError()
  • HTTP Requests: httpGet(), httpGetJSON(), httpPost(), httpPostJSON()
  • Artifact Discovery: discover(), discoverByDigest()

Building

This runs:
  1. esbuild - Bundles policy.js and SDK
  2. extism-js - Compiles bundle to WASM
Output:
  • dist/policy.js - Bundled JavaScript (~7KB)
  • policy.wasm - Compiled WASM (~2.1MB, includes QuickJS runtime)

Testing

test.sh:

JavaScript Compatibility

Supported:
  • ✅ ES2020 JavaScript features
  • ✅ JSON parsing and manipulation
  • ✅ String operations and regex
  • ✅ Arrays, objects, and basic types
  • ✅ Synchronous operations
Not Supported:
  • ❌ async/await (no Promise support)
  • ❌ Node.js built-ins (fs, path, http)
  • ❌ ES modules (use CommonJS)
  • ❌ Browser APIs (fetch, localStorage)
  • ❌ setTimeout/setInterval
  • ❌ Symbols and WeakMaps
Recommended:

Best Practices

  1. Use simple data structures - Plain objects and arrays
  2. Validate early - Check material format first
  3. Clear violation messages - Include specific details
  4. Use skip appropriately - Don’t fail for wrong material types
  5. Test with real data - Use actual artifacts
  6. Log progress - Aid debugging
  7. Handle errors - Use try-catch for parsing

Next Steps

Examples

Explore complete policy examples

Go SDK

Compare with the Go SDK