How can I create an online Rust compiler? Docker or VM?

It would be similar to Rust playground, but since I am building a DSL, there are some dependencies that are not included in the official playground. And of course, for better experience, I would like to have this online compiler on my own website. It should:

  • code in
  • binary out

Now I am studying Docker and VM, but not sure which one I should use. Any suggestions or tips?
Thank you so much in advance!

cc @shepmaster, I suspect they have thought about this more than anybody else out there :smile:


You could start from the Rust playground code: GitHub - integer32llc/rust-playground: The Rust Playground


If you understand Go you can also check out their playground repo.

Yup. In general handwavy terms, you "just" need to edit the Cargo.toml to include your crates, then build the 6 Docker images (stable, beta, nightly, rustfmt, clippy, miri). You'd build the frontend code and backend code and put them all together behind nginx.

The top-crates library / binary allow modifying the crates that are automatically included in the playground.

You can also see how we deploy the playground.


wow, thank you so much!

1 Like

General handwavey warning that Docker is not a security mechanism. Assume any way of running code, including bugs in your language, will let someone get control over the host machine.

Simplest option is to just host on a cloud provider with no permissions and cycle the machines regularly. (Or a managed Docker service like AWS Fargate that does the equivalent for you)