What’s the best way to run user-submitted code with a Node.js Express backend?

0
4
Asked By CreativeCoder42 On

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

Answered By DockerDev89 On

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.

Answered By CloudyWithAChance On

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.

Answered By SafetyFirst101 On

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.

Answered By LambdaLover99 On

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

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.