DEV Community

cursora
cursora

Posted on

How We Safely Run User Code in 13 Languages

If you're building a coding education platform, sooner or later you hit the question: how do you run a STRANGER's code without risking the rest of your system? At Cursora we solved this for 13 languages — from Python to Rust and Kotlin — and wanted to share how it works under the hood.

The problem

A student submits code. It needs to compile (or not), run, accept input, and return output — all within a few seconds, safely, for thousands of runs a day. The naive approach (eval() or a bare subprocess on the host) is a fast track to disaster: unrestricted network access, filesystem access, CPU/RAM.

Our approach: container-level isolation

Every code run goes into its own, ephemeral Docker container with:

  • network: none — zero network access, so even a malicious attempt has nowhere to "phone home" to
  • hard memory, CPU, and process-count (PID) limits — tuned per language (compiled languages like Java or Rust get higher floors than lightweight interpreters)
  • the container destroyed immediately after the run — no persistent state between attempts

For compiled languages (Java, C, C++, C#, Go, Rust, Kotlin) we first build the binary inside that same isolated, network-less environment, then run it — so the code can only ever use the standard library, no external packages or crates.

What about the live terminal?

A separate challenge is our Live Programming module — a multi-file interactive editor with a real terminal (XTerm.js) wired over WebSocket. Here the container needs to live longer than a single invocation — it's a long-lived, stateful TTY session that our code-executor's session manager keeps separate from the ephemeral test runs.

Why this matters if you're learning

This architecture lets you write, compile, and run real code — Python, JavaScript, TypeScript, Java, C, C++, C#, Go, Rust, Ruby, PHP, Kotlin, Bash — directly in your browser, with nothing to install locally, and we can guarantee your code will never put you or other learners on the platform at risk.

Want to try it yourself? cursora.org has hands-on programming courses with real projects and code challenges across all of the languages above.

Top comments (0)