This task can be performed using Whipcode
A low cost REST API for running untrusted code
Best product for this task

Whipcode
dev-tools
Whipcode provides a secure, isolated environment for running untrusted code, seamlessly integrating into your application. Let us handle the heavy lifting, so you can focus on building, scaling, and innovating your solution. - Support for 25+ languages - Custom compiler options and timeouts - Pay-per-use pricing model - Open source backend

What to expect from an ideal product
- Creates a sandbox environment that keeps untrusted code away from your main system
- Supports multiple programming languages without extra setup or configuration
- Monitors and kills harmful or stuck processes before they cause issues
- Lets you set custom rules and timeouts to control code execution
- Handles resource isolation and security patches automatically through their cloud service