containerd_shim_wasm/sandbox/
mod.rs1use std::fs::File;
2use std::io::Read;
3
4use anyhow::{Context, Result};
5use context::{RuntimeContext, Source};
6use path::PathResolve as _;
7
8pub mod context;
9pub(crate) mod path;
10
11#[trait_variant::make(Send)]
12pub trait Sandbox: Default + 'static {
13 async fn run_wasi(&self, ctx: &impl RuntimeContext) -> Result<i32>;
15
16 async fn can_handle(&self, ctx: &impl RuntimeContext) -> Result<()> {
23 async move {
25 let source = ctx.entrypoint().source;
26
27 let path = match source {
28 Source::File(path) => path,
29 Source::Oci(_) => return Ok(()),
30 };
31
32 path.resolve_in_path_or_cwd()
33 .next()
34 .context("module not found")?;
35
36 let mut buffer = [0; 4];
37 File::open(&path)?.read_exact(&mut buffer)?;
38
39 if buffer.as_slice() != b"\0asm" {
40 wat::parse_file(&path)?;
42 }
43
44 Ok(())
45 }
46 }
47}