Skip to content

feat(wasm): add sandbox host functions and extended ABI for term-challenge - #39

Merged
echobt merged 3 commits into
mainfrom
feat/wasm-sandbox-abi-support
Feb 17, 2026
Merged

feat(wasm): add sandbox host functions and extended ABI for term-challenge#39
echobt merged 3 commits into
mainfrom
feat/wasm-sandbox-abi-support

Conversation

@echobt

@echobt echobt commented Feb 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Add sandbox execution support to the WASM runtime and extend the challenge executor with new ABI entry points (get_tasks, configure) required by term-challenge modules.

Changes

WASM Executor (bins/validator-node)

  • Refactor memory allocation into allocate_input() helper that tries alloc(size) first, then falls back to allocate(size, align), and finally to a memory-offset fallback
  • Add execute_evaluation_with_sandbox() method accepting a SandboxPolicy
  • Add execute_get_tasks() to call the WASM get_tasks export and read result from linear memory
  • Add execute_configure() to write configuration data into WASM memory and invoke the configure(ptr, len) export
  • Register SandboxHostFunctions alongside existing NetworkHostFunctions during instantiation
  • Create challenges/ subdirectory under the WASM module dir on startup

WASM Runtime Interface (crates/wasm-runtime-interface)

  • Add SandboxPolicy type with default(), development(), and term_challenge() presets controlling allowed commands and execution time limits
  • Add sandbox module with host function registrar (platform_sandbox namespace), status codes, error types, and sandbox state management
  • Add sandbox_policy field to InstanceConfig and RuntimeState
  • Add call_i32_return_i32() helper to ChallengeInstance for single-arg WASM exports

Challenge Registry (crates/challenge-registry)

  • Add sandbox_policy: Option<SandboxPolicy> to WasmModuleMetadata with with_sandbox_policy() builder
  • Add sandbox_policy field to DiscoveredChallenge
  • Scan challenges/ subdirectory when discovering WASM modules
  • Load companion .policy.json files for sandbox/network policy configuration
  • Extract scan_wasm_dir() and load_sandbox_policy() helpers to reduce duplication

Extend the validator node WASM executor and challenge registry to support
term-challenge extended ABI with sandbox capabilities, new WASM exports
(get_tasks, configure), and improved memory allocation handling.

WASM Executor (wasm_executor.rs):
- Fix alloc/allocate handling: try alloc(size) first (1 param), then
  fall back to allocate(size, align) (2 params), then raw memory offset.
  Extracted into reusable allocate_input() helper.
- Add execute_get_tasks() to call get_tasks() export and read results.
- Add execute_configure() to write config data and call configure(ptr, len).
- Add execute_evaluation_with_sandbox() accepting SandboxPolicy alongside
  NetworkPolicy. Original execute_evaluation() delegates to it.
- Register SandboxHostFunctions during WASM instantiation.

Challenge Registry (registry.rs, discovery.rs):
- Add sandbox_policy field to WasmModuleMetadata with builder method.
- Add sandbox_policy field to DiscoveredChallenge.
- Load companion .policy.json files when discovering WASM modules.
- Scan challenges/ subdirectory alongside the main wasm_modules/ dir.
- Extract scan_wasm_dir() helper to reduce duplication.

WASM Runtime Interface (lib.rs, runtime.rs, sandbox.rs):
- Add SandboxPolicy type with default, development, and term_challenge
  presets controlling allowed commands and execution time limits.
- Add sandbox.rs module with SandboxHostFunctions implementing the
  platform_sandbox namespace (sandbox_exec, sandbox_get_tasks,
  sandbox_configure, sandbox_status host functions).
- Add SandboxHostState, SandboxHostConfig, SandboxHostError types.
- Add sandbox_policy to InstanceConfig and RuntimeState.
- Add call_i32_return_i32() to ChallengeInstance for single-arg exports.

Validator Node (main.rs):
- Create challenges/ subdirectory under wasm_module_dir on startup.
@coderabbitai

coderabbitai Bot commented Feb 17, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@echobt has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 4 minutes and 12 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/wasm-sandbox-abi-support

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

…-support

# Conflicts:
#	bins/validator-node/src/wasm_executor.rs
#	crates/wasm-runtime-interface/src/runtime.rs
…-support

# Conflicts:
#	crates/wasm-runtime-interface/src/lib.rs
#	crates/wasm-runtime-interface/src/runtime.rs
@echobt
echobt merged commit a58c786 into main Feb 17, 2026
20 of 21 checks passed
@echobt
echobt deleted the feat/wasm-sandbox-abi-support branch February 17, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant