My WASM Python Implementation Beat CPython (Without a JIT)
▲ 10 r/rust

My WASM Python Implementation Beat CPython (Without a JIT)

Okay. After seven months, I'm back.

Seven months ago I started writing a Python interpreter from scratch in Rust, compiled to wasm (less than 200kb of bandwith). Edge Python is a sandboxed subset of Python that runs in the browser and the terminal, and code can't touch files or the network unless you allow it.

It started as a lexer and a simple stack VM, and over about 1,600 commits it grew a CLI, a package registry, snapshots, actors and a browser playground. It's just me building it.

Last week it was still 3x slower than CPython. I rewrote the VM this weekend on top of the SSA form I already had, and now the wasm build beats native CPython on loops.

Edge (wasm) CPython (native)
Integer loop 154 ms 232 ms
Float math 231 ms 307 ms
Dicts 372 ms 62 ms
Strings 196 ms 35 ms

The trick was a register VM, and Rust made it fit in wasm with NaN-boxed values and no runtime. It still loses on dicts and strings, so that's next.

Try to break my numbers :)

Website: https://edgepython.com/

GitHub: https://github.com/dylan-sutton-chavez/edge-python

u/Healthy_Ship4930 — 11 days ago

Isolated Python Sandbox for Agents

okey, here is my small project :).

edge python is a runtime where nothing reaches anything outside the virtual machine unless edge.json grants it.

written in rust (wasm), 200kb of bandwidth. runs in the browser, the cli and everywhere.

grants are per host and per package, so it's a good place to run code you don't trust like plugins inside your app, agent tool calls or user scripts.

still working on the beta, so don't use it for anything important, but any feedback is welcome :).

reddit.com
u/Healthy_Ship4930 — 15 days ago

How my Python compiler runs 100,000 isolated VM's on a single $3 server.

https://preview.redd.it/7iwifrb77tjh1.png?width=2935&format=png&auto=webp&s=f91bffa7010abfee6d9d5354598668abef0de110

I wrote a Python compiler and VM in Rust over the last six months. It compiles a sandboxed Python subset directly to SSA bytecode in a single pass with no AST.

The engine ships as a 200KB WASM binary or a native CLI tool. The feature that I'm working on is the worker swarm. I can declare one hundred thousand replicas in a YAML file and run them on a cheap VPS. Workers spawn on demand, each gets its own heap, and they share nothing. Message passing is the only way they communicate.

There is also an eval mode where you POST Python snippets to an HTTP endpoint. Each snippet compiles into its own isolated program, runs in its own VM, and dies when done. If it crashes it retries and drops. If it hangs a preempt kills it.

By default programs get no file system, no network, and no environment access. There is no eval function, no exec function, and no dynamic imports in the language. The only way untrusted code runs is through this eval path with hard limits on memory, operations, and CPU time. I built this to safely execute generated code or user submissions without Docker or heavy virtualization.

I would love to hear if you would trust an architecture like this for running untrusted code and what you would do differently.

https://edgepython.com/

reddit.com
u/Healthy_Ship4930 — 2 months ago

Ask: Would you buy a Bambu Lab for microchips?

For six months I have been building, in the open, the software layer of a machine that does not exist yet. Untrusted recipes run fully sandboxed, compile to deterministic bytecode so one design produces identical physical actions on every machine, and the interpreter snapshots its full state so an hours long job survives a power cut and resumes byte for byte. Useless for a to do app. Mandatory if the hardware is writing transistors.

The machine fabricates real working microtransistors and simple chips on a desktop. Printer sized. Cartridges in, tested die out, a marketplace of designs in between. My nights lately are precursor chemistry and thermogravimetry papers, not code.

Not 2 nm. The method allows features of a few hundred nanometers from a machine that is small and cheap.

At 1,000 to 1,500 dollars, would this be on your bench. What would you fabricate first. What would make it useless to you.

Process details come after filing. The software is open source. I built that layer first, and now I am moving to the precursor side.

reddit.com
u/Healthy_Ship4930 — 2 months ago
▲ 179 r/Compilers

My hobby compiler is now compiling a company's production app

When I started programming Edge Python more than six months ago, I was looking for a version of Python that weighed less than 200 kb so it could reach any device, sandboxed by design, built with browsers in mind, decoupled from the operating system and very fast.

Today the closest competitor would be MicroPython. However, it did not solve my real problems or the problems of the people who use the project.

  • Managing async and blocking code on the event loop. MicroPython inherits CPython's blocking execution model, designed around the GIL. When I built Edge Python I put the events inside the virtual machine, and that lets you run any operation while handling thousands of connections without blocking the main thread or the worker's thread.
  • MicroPython was not built for the web and neither was its stdlib. I have been working to get regex and every other dependency down to a few clean lines, crash free thanks to directed fuzzing.
  • Edge Python guarantees parsing everything in linear time, in a single pass, while MicroPython does not. This came from avoiding a syntax tree, which makes programs parse faster.
  • MicroPython crosses into JS through PyProxy. Edge Python avoids that entirely with an execution model decoupled from the host, they never have to interact directly.
  • I recently added the ability to serialize entire programs, born from an issue. If a user closes the tab, the whole bytecode state gets serialized, stored in the browser cache, and when the user comes back execution continues from the exact same point.

That said, my intention was never to replace CPython and it never will be. It has a gigantic ecosystem and competing with it is not even a priority for me. What I want to enable is this.

  • Anyone with business logic written in Python being able to run it on the client side.
  • Running lightweight LLM logic on the client side, so you do not need expensive compute just to parse a CSV or do math.
  • Building a framework to run lightweight machine learning models entirely on the user's side.

I am still working on all of this and, to be honest, I do not know how long it will take me to reach a real version to build a product around. I just want to say it has been an incredible process, and it has made me realize that with a compiler of barely under 20,000 lines I spend less and less time writing code and more time automating its stability with fuzzing and determinism.

Thanks! Any feedback or experience is appreciated. If you want to take a look, try the demo in the browser at edgepython.com and edit the code, the compiler is really fast. Try the CLI version too.

u/Healthy_Ship4930 — 3 months ago

I embedded a Python compiler directly in my docs and loads in under 200ms, any feedback?

Hey! For the past four months I've been working on my compiler, and this week I've been refining my documentation using Nextra and embedding the compiler directly into the docs with editable React components, any feedback? :)

Downloading the compiler and component takes around 200ms, with the entire compiler weighing in at 200KB. It has also been fuzz tested across 16 cores for a total of 14 days of core-time without a single crash, using a seed corpus of 2200 inputs.

Try it out here: edgepython.com, any thoughts?

u/Healthy_Ship4930 — 4 months ago

One Week Building the Testing Infrastructure with Docker and Rust for my Compiler

Hey everyone! Quick update on the fuzzer for edge python compiler :)

I wanted to share how I set up some infrastructure with Docker Compose to fuzz my compiler across multiple cores; what I did and what I learned because the implementation is very small but each decission tought me lot of time.

What's fuzzing? It's creating unexpected, or malformed input at a program to shake out bugs, crashes, and vulnerabilities. There are several approaches, but this is the one I went with.

I started by reusing the corpus from my unit tests

A little script turns the cases into a seed corpus (one file per program, so the fuzzer starts from inputs that already exercise most of the language) and a token dictionary of keywords, operators, and builtins. The fuzzer uses that dictionary to splice in real tokens defined by the lexer (here).

Next you pick a framework that fits your stack. My compiler is in Rust, so I used cargo-afl, the Rust tool for AFL++ (one of the best-known fuzzers out there; if you are in C or C++ the equivalent would be libFuzzer). From there you define a target: mine takes the raw input bytes as source code and runs them through lex, parse and VM (reference).

At that point you can already run a campaign on a single core. To actually scale it, I run everything in one container on an 8 core server (using docker). Inside that container the deploy script spins up one AFL instance per core and one "main", where they share the same output directory and sync their queues:

It's a small setup and I'm sure there are best ways to do it, but it's a solid starting point if you've got a compiler of your own. In the early days I'd pull around 10 crashes in a single hour. Now that Ive fixed all the shallow bugs, it takes the fuzzer almost a full day to surface even one. Classic coverage saturation, and honestly a pretty satisfying sign of progress :)!

My implementation: https://github.com/dylan-sutton-chavez/edge-python/tree/main/compiler/fuzz-afl

Docs: https://edgepython.com/implementation/fuzzing

u/Healthy_Ship4930 — 4 months ago
▲ 16 r/Compilers+1 crossposts

Fuzzing my compiler with cargo-afl

Couple days ago I included a fuzzer at edge-python, my less 200KB WASM Python compiler set, just to take a look what break. I Used cargo-afl, in a full run from the lexer and parse to VM on raw bytes.

First run: 346 "crashes" in five minutes. I panicked a bit (working four months on this and see that everyting breaks), then realized "American Fuzzy Lop" only flags actual signals, so since cargo AFL build turns panics into aborts, every one was a genuine an error, not noise.

Triaged them with a quick grep "panicked at" | sort | uniq -c... and basically all 346 were the same bug, where my string literal parser did &s[1..s.len()-1], and some edge cases included my crashes drop down.

Now is more stable, executing for 7 minutes now just find 9 crashes.

If anyone's done this on a lexer/parser/VM, what else is worth throwing at it?

To take a look to a bit more, I made a small documentation on my compiler docs edgepython.com

u/Healthy_Ship4930 — 4 months ago
▲ 379 r/rust

13K Lines of Rust Later: From Toy Compiler to Production Runtime in 90 Days

Hi! Software is never really done, but my compiler finally feels "finished," so I wanted to share it.

Its Edge Python, a sandboxed Python subset that compiles to one around 170KB WASM module and runs anywhere WASM does (browser, Cloudflare Workers, Wasmtime). 13,000 lines of no_std Rust. I always loved Python syntax and wanted to run it everywhere, safely, for the web.

Where in these 90 days the project got a sponsor, who is interested in running more than 7k lines of Python on the client side to save computation and reduce latency (zero codebase changes, just a packages.json file).

Here's a little bit about this compiler:

In CPython, await only works inside async def, so asyncness infects the whole call chain. I moved te scheduler into the VM instead. Coroutines are heap objects with fully snapshotted state, so a suspension point (sleep, receive, fetch) can fire from any function, even a plain def or module top level (all of this based on the wonderfull tokio package).

The VM snapshots the live frame, parks it on the enclosing coroutine, and walks frames inside-out on resume. try/except survives it.

def setup(label):
    sleep(0) # suspends inside an ordinary def, no async/await
    return f"ready:{label}"
print(setup("x")) # works at module top-level too

Structured concurrency (gather, with_timeout, run, cancel) ships as builtins, and the VM never reimplements an event loop: it parks a coro as WaitingHostCall(id) and lets the hosts loop (a browser Promise, Wasmtime) signal readiness.

With no host time hook,sleep() runs on a deterministic virtual clock, so concurrent code is instant and reproducible under test.

One more for this crowd: the bytecode is SSA-versioned with Phi at control-flow joins, which you rarely see in a stack VM this small. A hand-written Pratt parser emits it directly, no AST in between.

Demo: demo.edgepython.com
Docs: edgepython.com
GitHub: github.com/dylan-sutton-chavez/edge-python

Happy to go deep on the suspension mechanism or the inline caches. Feedback welcome.

u/Healthy_Ship4930 — 5 months ago

From a Toy Compiler to a Production-grade Compiler in 90 days :)

Hi! Software is never really done, but my compiler finally feels "finished," so I wanted to share it.

Its Edge Python, a sandboxed Python subset that compiles to one around 170KB WASM module and runs anywhere WASM does (browser, Cloudflare Workers, Wasmtime). 13,000 lines of no_std Rust. I always loved Python syntax and wanted to run it everywhere, safely, for the web.

Otherwise, in CPython, await only works inside async def, so asyncness infects the whole call chain. I moved the scheduler into the VM instead. Coroutines are heap objects with fully snapshotted state, so a suspension point (sleep, receive, fetch) can fire from any function, even a plain def or module top level.

The VM snapshots the live frame, parks it on the enclosing coroutine, and walks frames inside-out on resume. try/except survives it.

def setup(label):
    sleep(0) # suspends inside an ordinary def, no async/await
    return f"ready:{label}"
print(setup("x")) # works at module top-level too

Structured concurrency (gather, with_timeout, run, cancel) ships as builtins, and the VM never reimplements an event loop: it parks a coro as WaitingHostCall(id) and lets the hosts loop (a browser Promise, Wasmtime) signal readiness.

With no host time hook,sleep() runs on a deterministic virtual clock, so concurrent code is instant and reproducible under test.

One more for this crowd: the bytecode is SSA-versioned with Phi at control-flow joins, which you rarely see in a stack VM this small. A hand-written Pratt parser emits it directly, no AST in between.

Demo: demo.edgepython.com - Docs: edgepython.com - GitHub: github.com/dylan-sutton-chavez/edge-python

Happy to go deep on the suspension mechanism or the inline caches. Feedback welcome.

u/Healthy_Ship4930 — 5 months ago

Edge Python a 170 KB sandboxed Python subset (WASM) for running agent-generated code client-side (directly in the browser)

Sandboxing Python for LLM/agent-generated code is usually done with containers, microVMs, or server-side WASM runtimes.

I wanted something that runs in the browser tab itself: no server, no round-trip, no host process. So I spend few months writing a bytecode compiler + stack VM in Rust that ships as a standalone 170 KB WASM.

The demo is a Rosenblatt perceptron training on an OR gate entirely in the browser. Language surface covers classes, async/await, pattern matching, decorators, generators, f-strings... enough for non-trivial agent code.

A bit of the design:

  • Sandboxed by construction; per-VM caps on heap, ops, call depth.
  • Native modules ship as separate .wasm via a sealed plugin ABI (handle-based, language-agnostic).
  • Optional SHA-256 integrity on URL imports; content-addressed cache with drift detection.
  • No stdlib by design, host explicitly grants every capability the script can touch.

Happy to discuss :). Links in the comments.

reddit.com
u/Healthy_Ship4930 — 5 months ago

A "Japanese developer" offered me $3K/month to be his face with US clients. Here's the full email thread

Hey all,

A few months ago I started pushing side projects to my GitHub after work. This week I got a cold email from a guy claiming to be a Japanese developer named "Masaru" offering me $3K/month for around 2 hours/week. He said that I wouldn't write any code. I just need to be the "face" with his US clients (calls, communication, etc.) while he does the dev work from Japan.

Too good to be true, obviously. I dug around and found that this exact pitch is a documented pattern. There is a 2024 Hacker News thread ("Ask HN: The Japanese Developer Scam") describing the email.

Security firms (Strider Intel, KELA, SEAL Intel) and the US have linked variants of this to the worker scheme: someone in a friendly time zone is used as an identity proxy to land Upwork/Fiverr/US company contracts.

The proxy lends their face, their bank account, their IP, sometimes even ships to address for a company laptop.

Herre is the email thread below (his email address left intact so people searching it land here).

[Masaru Nakamura <masaru.nakamura92127@gmail.com>]
Hi there,

I found your GitHub while searching for thoughtful Python engineers - your work is exactly what I was hoping to find.

I'm Masaru. I'm a software developer in Japan with a full-stack and ML background. I'm starting a new business I genuinely believe in, and I'm looking for a partner based somewhere in the Americas (US, Mexico, Brazil, Argentina, or anywhere in a US-overlapping time zone) - someone to share the upside and help shape this from early on.

Time commitment is small (2–3 hours/week). Revenue share is 20%, around $2K–$3K/month currently.

Happy to share everything if you're curious.

Best regards,
Masaru

---

[Me]
Hey Masaru

That sounds interesting, please tell me more.

Regards.

---

[Masaru Nakamura <masaru.nakamura92127@gmail.com>]
Thank you for your email.

I’d like to explain why I’m looking for a collaborator.

The job market between the U.S. and Japan is significantly different, often with rates being 2 to 3 times higher in the U.S. Because of this, I’ve focused on working with American clients. I typically work at night and sleep during the day due to the time zone difference. However, despite adjusting my schedule, American clients often hesitate to hire me because they’re uncomfortable with the time zone difference or concerned about communication due to our non-fluent English.

To address this, I’ve been looking to collaborate with a LATAM developer who can handle client communication, while I focus on the development work. You wouldn’t need to do any development yourself. From my experience, this role usually requires about 2 hours per week, and it’s a very important one. Therefore, I’d be offering 20-25% of the total income, which would be about $2K - $3K per month.

I’m not looking for just anyone—I’m specifically seeking someone with solid development experience. Even though I don’t require coding from the collaborator, without development experience, it would be difficult to manage client communication properly and understand project requirements.

That’s why I came across your profile on GitHub and decided to reach out to you.

If you’re open to this type of collaboration, I’d be happy to share more details about the workflow.

Thanks again, Masaru

Has anyone else been getting this lately? Curious whether the 20-25% / "you handle the calls" variant is new or has been circulating for a while.

Please share your thought :).

news.ycombinator.com
u/Healthy_Ship4930 — 5 months ago

Has anyone else hit this 600ms memory.grow cost on Copilot+ PCs? Why is nobody talking about it?

Month four building my own embedded Python runtime in Rust 145kb release, runs in-browser via WASM. demo.

Tested it across a bunch of hosts this week and hit something I can't find documented anywhere: on machines with virtualization-based security enabled (HVCI/VBS default on every Copilot+ PC with Snapdragon X Elite), every memory.grow call in WASM costs ~0.2ms. Not microseconds. The hypervisor validates EPT page mappings before handing them to V8, and that round-trip is the whole cost.

My demo does ~3,000 allocs per run. I was using LeakingPageAllocator from lol_alloc the one in every README which calls memory.grow(1) on every alloc. 3,000 × 0.2ms = ~600ms of pure grow overhead before a single line of Python executes. Edge on Snapdragon X Elite: ~5s to feel responsive. Same WASM on Linux/macOS: under 50ms. 100x cold-start difference, same module, same V8.

Fix was a one-line swap to LeakingAllocator a real bump pointer that grabs pages in bulk and bumps within them. ~50 grows instead of 3,000. Cold start dropped to ~10ms.

#[global_allocator]
static A: AssumeSingleThreaded<LeakingAllocator> =
    unsafe { AssumeSingleThreaded::new(LeakingAllocator::new()) };

The leak is fine here the JS host throws away the WASM instance between runs, so working set is bounded and the OS reclaims everything on teardown.

What I want to know: is anyone else benchmarking WASM cold-start on Copilot+ PCs? The default allocator everyone copies from lol_alloc's README is genuinely the worst choice for these machines, and Microsoft is pushing them hard. If you've shipped WASM in Edge on a Snapdragon X Elite and measured, what did you see? Is this a lol_alloc gotcha or a general "VBS makes memory.grow expensive" thing?

Happy to answer questions about the runtime parser, VM, GC, plugin ABI, whatever.

u/Healthy_Ship4930 — 5 months ago