{"by":"mavdol04","descendants":25,"id":46871387,"kids":[46880132,46873036,46876315,46872369,46872625,46874424,46873177,46881921,46872700],"score":76,"text":"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\n\n  @task(\n      name=&quot;analyze_data&quot;, \n      compute=&quot;MEDIUM&quot;,\n      ram=&quot;512mb&quot;,\n      allowed_files=[&quot;.&#x2F;authorized-folder&#x2F;&quot;],\n      timeout=&quot;30s&quot;, \n      max_retries=1\n  )\n  def analyze_data(dataset: list) -&gt; dict:\n      &quot;&quot;&quot;Process data in an isolated, resource-controlled environment.&quot;&quot;&quot;\n      # Your code runs safely in a Wasm sandbox\n      return {&quot;processed&quot;: len(dataset), &quot;status&quot;: &quot;complete&quot;}\n</code></pre>\nAnd in TypeScript we have a wrapper:<p><pre><code>  import { task } from &quot;@capsule-run&#x2F;sdk&quot;\n\n  export const analyze = task({\n      name: &quot;analyzeData&quot;, \n      compute: &quot;MEDIUM&quot;, \n      ram: &quot;512mb&quot;,\n      allowedFiles: [&quot;.&#x2F;authorized-folder&#x2F;&quot;],\n      timeout: 30000, \n      maxRetries: 1\n  }, (dataset: number[]) =&gt; {\n      return {processed: dataset.length, status: &quot;complete&quot;}\n  });\n</code></pre>\nYou 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>","time":1770128881,"title":"Show HN: Sandboxing untrusted code using WebAssembly","type":"story","url":"https://github.com/mavdol/capsule"}