I'm trying to create a platform similar to those live coding sites where users can submit code in multiple languages like Bash, Python, Rust, Ruby, etc., and see the output in real-time. I'm using Node.js with an Express backend and I'm exploring options for safely running user-submitted code. Here are a few options I'm considering:
1. Running the code directly on the EC2 instance – this seems really risky.
2. Using Docker containers – I'm curious about pros/cons and how long each container should run.
3. Running within an AWS Elastic Container Service Task – what do I need to know here?
I'd love your suggestions on these options and any other methods you might recommend. Also, how should I handle queuing for submissions, returning data to users, and showing real-time streams of terminal commands like package downloads?
4 Answers
When users submit code, you should spawn a new Docker container each time with a set timeout. If they come back later and hit 'run' again, it should indeed start another fresh container for that session. If users need to store files, think about how you'll handle that, too, during multiple submissions.
Cloudflare Workers could be another option, but it sounds like you need to stick with AWS. Using Docker containers would work really well—just create a fresh container for each code submission and tear it down afterward. A timeout of around 5-10 seconds should help manage costs on AWS. Using something like BullMQ for queuing and streaming results via WebSocket will give you real-time feedback for users.
Definitely don't run user-submitted code directly on your EC2 instance. That's a recipe for disaster! Containerization is a good approach, but you need to ensure high security—consider using separate containers for each language to avoid cross-contamination of commands. It's crucial to prioritize safety above all else.
Have you thought about using AWS Lambda? It’s a great option because it's already sandboxed and can handle multiple languages. Instead of overcomplicating with a queue system, just set up a simple HTTP endpoint to execute code submissions and return results to users directly. As for the output stream, Lambda supports streaming, so you can easily send real-time updates back to users.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically