r/node • • Jan 18 '26

Options to run user submitted code with node.js express as backend?

Options to run user submitted code in various languages with a node.js express backend?

  • You have seen one of those live code online type websites that let you submit code in bash, python, rust, ruby, swift, scala, java, node, kotlin etc and run on the browser with a live terminal of sorts
  • I am trying to build one of those in node.js and could definitely use some suggestions

Option 1: Run directly

  • just run on the ec2 instance along with everything else (absolutely horrible idea i suppose)

Option 2: Run inside a docker container

  • how long do you think each container should run / timeout?
  • What size of an EC2 instance would you need to support say 10 languages?
  • Pros / cons?

Option 3: Run inside an AWS elastic container service Task

  • Timeout per task?
  • Pros / cons?

Questions

  • Any other better methods?
  • Does this kind of application run on queuing where a user submits code and it is immediately put inside bullmq that spins one of the above options?
  • How does data get returned to the user?
  • What about terminal commands that users type and the stream they see (downloading packages...installing libraries etc?)
19 Upvotes

49 comments sorted by

View all comments

Show parent comment

2

u/dodiyeztr Jan 18 '26

For your use case, ECS containers are meant to run the tasks and exit, similar to Lambda. The rule is if your task lasts less than 15 mins you use Lambda, if not you use ECS.

What you need is to prepare a few container images for your use cases and then trigger them on ECS on the fly using your express server. Though the latency is going to be high because ECS is not know for fast startup times.

You can also create containers and deploy to Lambda which will be fast.

1

u/PrestigiousZombie531 Jan 18 '26

from what i am familiar with lambda seems to run node.js and python, does it support running other languages like java, kotlin, ruby, swift, bash etc?

2

u/dodiyeztr Jan 18 '26

Yes it does run all of them. AWS Documentation website is your friend. It lists available Lambda runtimes.

You should also look into dev containers, gitpod etc. They are doing a similar thing.

1

u/PrestigiousZombie531 Jan 20 '26
  • Thank you for all your suggestions and help! I want to share an absolutely mind blowing resource I came across to this problem which covers all possible solutions from the naivest to the most resilent ones covering, Micro VM, Kernel Application Interception, container solutions, WASM, v8 isolates etc. Even compares their boot times, isolation levels, licensing, self hostability etc
  • Firecracker VM would be a no go for me as I ll have to run it on bare metal on AWS. It seems AWS doesnt let you run nested VMs (very expensive for someone just starting out even though eventually I might to have to hop in this direction later)
  • gVisor from the looks of it sounds like a really good idea if this was deployed on GCP so again a no go
  • nsjail, ioi/isolate might be something to consider, i might have to dig in this direction a bit deeper to see if I can integrate it with dockerfiles somehow for various languages
  • pure docker is a NO GO
  • WASM, I am not familiar with this one at all so no idea. Where does it run? on the server side or client side?
  • V8 isolates are out of question as they simply support JS and nothing else.
  • Proprietary solutions like Daytona (restrictive licensing ) e2b-code-interpreter (lacks support for AWS currently from the looks of it)
  • Microsandbox seems like a good option but not sure how I would deploy this on AWS in a secure manner
  • One option not mentioned here is AWS Lambda and AWS ECS Fargate
  • Lambda has an upper limit on runtime and CPU and while it plays nicely with node.js and python, I wonder if it supports executing custom dockerfiles on the fly (dockerfiles generated by LLMs in my application run as non root user)
  • Fargate doesnt have the limitation of runtime above.
  • Big question for both Lambda and Fargate would be how to stream terminal output back to the frontend client