daypress
admin route/d-admin/wasm
doc versionv1.0.4
reading time7 min read
section group25 · AI, Wasm & Headless API
Docs/AI, Wasm & Headless API
/d-admin/wasm7 min readv1.0.4

Sandboxed WebAssembly (.wasm) Extensions & Host ABI v1

Unlike WordPress PHP plugins—which share global process memory, filesystem access, and raw SQL credentials—Daypress custom extensions execute inside deterministic WebAssembly sandboxes (crates/daypress-wasm) with zero ambient host authority.

Sandbox limits & capability model

Every installed .wasm module in Plugins → Wasm Crates (/d-admin/wasm) is instantiated fresh per invocation with deterministic resource ceilings and an explicit capability allowlist:

Boundary / CapabilityDefault / ScopeEnforcement
Instruction Fuel Budget50,000 fuel units (configurable up to 5,000,000)Infinite loops trap immediately with FuelExhausted without stalling Tokio worker threads.
Linear Memory Ceiling16 Wasm pages (1 MiB default, max 64 pages / 4 MiB)Out-of-bounds growth is denied inside the module's isolated linear memory.
shortcodeRegister [your_shortcode]Allows the module's exported render_shortcode() function to emit HTML fragments.
content_filterPost body filter pipelineAllows exported filter_content() to read UTF-8 input via dp_input_len / dp_read_input.
read_public_optionsblogname, blogdescription, siteurl, home, WPLANG, timezone_stringSecrets, SMTP passwords, session keys, and arbitrary SQLite tables are never exposed.
kv_read / kv_writeExtension-scoped KV namespaceIsolated key-value state stored per extension slug in daypress_wasm_kv.
/d-admin/wasm · Sandboxed WebAssembly (.wasm) Extensions
Daypress Wasm Extensions manager displaying installed .wasm modules, ABI v1 status, fuel limit, memory ceiling, and capabilities
Wasm Crates screen (/d-admin/wasm): inspect fuel budgets, memory pages, granted capabilities, live test output, and the zero-toolchain template compiler.

In-admin Wasm shortcode compiler

Need a fast dynamic badge, hit counter, or site-title banner without installing a local Rust toolchain? Use the Quick Wasm Shortcode Compiler directly inside /d-admin/wasm:

  1. Enter an extension Slug (e.g. release-badge) and Shortcode Tag (e.g. release_badge).
  2. Write your HTML snippet using safe host placeholders such as {{option:blogname}}, {{attr:label}}, {{kv_get:banner_note}}, or {{kv_incr:views}}.
  3. Click Compile & Install .wasm. Daypress synthesizes a valid \0asm binary targeting Host ABI v1, persists its SHA-256 hash in daypress_wasm_extensions, and activates [release_badge label="v1.0.4"] immediately.

Authoring a Rust wasm32 crate (Host ABI v1)

For custom business logic, pricing calculators, or syntax transformers, compile any Rust cdylib crate targeting wasm32-unknown-unknown against the locked Daypress Wasm Host ABI v1 imports in module env:

rust (wasm32-unknown-unknown)
// src/lib.rs — cargo build --target wasm32-unknown-unknown --release
#[link(wasm_import_module = "env")]
extern "C" {
    fn dp_abi_version() -> i32; // Always returns 1 on v1.x
    fn dp_emit_str(ptr: *const u8, len: i32) -> i32;
    fn dp_emit_attr(key_ptr: *const u8, key_len: i32, fb_ptr: *const u8, fb_len: i32) -> i32;
    fn dp_emit_option(opt_ptr: *const u8, opt_len: i32) -> i32;
    fn dp_kv_incr_emit(key_ptr: *const u8, key_len: i32, delta: i64) -> i64;
}

fn emit(s: &str) {
    unsafe { let _ = dp_emit_str(s.as_ptr(), s.len() as i32); }
}

#[no_mangle]
pub extern "C" fn render_shortcode() -> i32 {
    emit("<span class="dp-wasm-pill">");
    unsafe {
        let _ = dp_emit_attr(b"prefix".as_ptr(), 6, b"Reads: ".as_ptr(), 7);
        let _ = dp_kv_incr_emit(b"page_reads".as_ptr(), 10, 1);
    }
    emit("</span>");
    0
}
Locked Host ABI v1 Contract: All 10 host imports in env (dp_abi_version, dp_emit_str, dp_emit_i64, dp_emit_option, dp_emit_attr, dp_kv_get_emit, dp_kv_set, dp_kv_incr_emit, dp_input_len, dp_read_input) and both guest exports (render_shortcode, filter_content) are frozen across all 1.x releases.

Managing & testing via MCP & REST

AI agents and CI pipelines can list, compile/install, execute dry-run sandbox tests, or remove extensions via daypress_manage_wasm_extensions or /wp-json/daypress/v1/wasm-extensions:

json (MCP tools/call)
{
  "name": "daypress_manage_wasm_extensions",
  "arguments": {
    "action": "execute",
    "slug": "release-badge",
    "attrs": { "label": "Stable v1.0.4" },
    "input": ""
  }
}