Docker based online judge

I am building an online judge to run and compile code using docker containers.
I want to isolate each code submission and hence would run them in isolated containers for security reasons and for limiting resources (spawn a new container on request and destroy it after compiling and running the test code). What are the possible solutions to deploy such a project? Is there any service which allows the developer to spawn temporary containers on the go?
I’m looking for a budget friendly solution. The current solution I have in the back of my head is to have a VM(on GCP or AWS EC2) and have a server running on it. It would in turn spawn new containers for every request. Is this the most optimal solution?