12 releases (1 stable)

Uses new Rust 2024

new 1.0.0 Apr 23, 2025
1.0.0-rc.1 Mar 28, 2025
0.10.0 Mar 5, 2025
0.8.0 Dec 4, 2024
0.1.2 Mar 7, 2023

#93 in WebAssembly

Download history 5/week @ 2025-01-06 26/week @ 2025-01-13 124/week @ 2025-01-27 33/week @ 2025-02-03 21/week @ 2025-02-10 11/week @ 2025-02-17 4/week @ 2025-02-24 149/week @ 2025-03-03 19/week @ 2025-03-10 13/week @ 2025-03-17 121/week @ 2025-03-24 39/week @ 2025-03-31 10/week @ 2025-04-07 8/week @ 2025-04-14 125/week @ 2025-04-21

202 downloads per month

Apache-2.0

370KB
5K SLoC

runwasi logo

containerd-shim-wasm

A library to help build containerd shims for Wasm workloads.

Usage

To implement a shim, simply implement the Shim and Sandbox trait:

use containerd_shim_wasm::{
    shim::{Shim, Config, Cli, Version, version},
    sandbox::Sandbox,
    sandbox::context::RuntimeContext,
};
use anyhow::Result;

struct MyShim;

#[derive(Default)]
struct MySandbox;

impl Shim for MyShim {
    type Sandbox = MySandbox;

    fn name() -> &'static str {
        "my-shim"
    }

    fn version() -> Version {
        version!()
    }
}

impl Sandbox for MySandbox {
    async fn run_wasi(&self, ctx: &impl RuntimeContext) -> Result<i32> {
        // Implement your Wasm runtime logic here
        Ok(0)
    }
}

MyShim::run(None);

The Engine trait provides optional methods you can override:

  • can_handle() - Validates that the runtime can run the container (checks Wasm file headers by default)
  • supported_layers_types() - Returns supported OCI layer types
  • precompile() - Allows precompilation of Wasm modules
  • can_precompile() - Indicates if the runtime supports precompilation

The resulting shim uses Youki's libcontainer crate to manage the container lifecycle, such as creating the container, starting it, and deleting it, and youki handles container sandbox for you.

Running the shim

containerd expects the shim binary to be installed into $PATH (as seen by the containerd process) with a binary name like containerd-shim-myshim-v1 which maps to the io.containerd.myshim.v1 runtime. It can be configured in containerd.

This crate is not tied to any specific wasm engine.

Check out these projects that build on top of runwasi:

Dependencies

~38–58MB
~1M SLoC