Hacker News Viewer

Show HN: Sandboxing untrusted code using WebAssembly

by mavdol04 on 2/3/2026, 2:28:01 PM

Hi everyone,<p>I built a runtime to isolate untrusted code using wasm sandboxes.<p>Basically, it protects your host system from problems that untrusted code can cause. We’ve had a great discussion about sandboxing in Python lately that elaborates a bit more on the problem [1]. In TypeScript, wasm integration is even more natural thanks to the close proximity between both ecosystems.<p>The core is built in Rust. On top of that, I use WASI 0.2 via wasmtime and the component model, along with custom SDKs that keep things as idiomatic as possible.<p>For example, in Python we have a simple decorator:<p><pre><code> from capsule import task @task( name=&quot;analyze_data&quot;, compute=&quot;MEDIUM&quot;, ram=&quot;512mb&quot;, allowed_files=[&quot;.&#x2F;authorized-folder&#x2F;&quot;], timeout=&quot;30s&quot;, max_retries=1 ) def analyze_data(dataset: list) -&gt; dict: &quot;&quot;&quot;Process data in an isolated, resource-controlled environment.&quot;&quot;&quot; # Your code runs safely in a Wasm sandbox return {&quot;processed&quot;: len(dataset), &quot;status&quot;: &quot;complete&quot;} </code></pre> And in TypeScript we have a wrapper:<p><pre><code> import { task } from &quot;@capsule-run&#x2F;sdk&quot; export const analyze = task({ name: &quot;analyzeData&quot;, compute: &quot;MEDIUM&quot;, ram: &quot;512mb&quot;, allowedFiles: [&quot;.&#x2F;authorized-folder&#x2F;&quot;], timeout: 30000, maxRetries: 1 }, (dataset: number[]) =&gt; { return {processed: dataset.length, status: &quot;complete&quot;} }); </code></pre> You can set CPU (with compute), memory, filesystem access, and retries to keep precise control over your tasks.<p>It&#x27;s still quite early, but I&#x27;d love feedback. I’ll be around to answer questions.<p>GitHub: <a href="https:&#x2F;&#x2F;github.com&#x2F;mavdol&#x2F;capsule" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mavdol&#x2F;capsule</a><p>[1] <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=46500510">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=46500510</a>

https://github.com/mavdol/capsule

Comments

by: yohguy

It looks really promising but I would love more examples as to how to actually use this with AI agents. Reading the homepage it is not clear if we are meant to have the Agent spun up and act fully in the sandbox (something like the HTTP example) or do we take the result code message from an AI agent and then run it dynamically (with eval?).<p>That being said this is useful even if it wasn&#x27;t for the running AI agent code aspect, being able to limit ram and cpu usage and time outs makes it easier to run coding based games&#x2F;applications safely (like battle snakes and Leetcode)

2/3/2026, 4:23:39 PM


by: gregpr07

Why go this route? Why Python is more powerful than JS is mostly because of third party plugins like pandas which are excplicitly not supported (C bindings, is this possible to fix?)...<p>At that point it might be just easier to convince the model to write JS directly

2/3/2026, 3:56:31 PM


by: simonw

The decorator syntax is neat but confusing to me - I would need to understand exactly what it&#x27;s doing in order to trust it.<p>I&#x27;d find this a lot easier to trust it if had the Python code that runs in WASM as an entirely separate Python file, then it would be very clear to me which bits of code run in WASM.

2/3/2026, 4:32:48 PM


by: koolala

It seems import to highlight these more. Aren&#x27;t all the limitations of using this based around their limitations?<p>componentize-py – Python to WebAssembly Component compilation<p>+<p>jco – JavaScript toolchain for WebAssembly Components<p>I&#x27;m curious how Wasi 0.3 cross language components will go for something like this.

2/3/2026, 3:41:15 PM


by: asyncadventure

[dead]

2/3/2026, 4:01:25 PM