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
- Runs code in isolated containers so malicious code can't break your server
- Supports all popular programming languages without installing them on your server
- Handles resource limits and timeouts to prevent server overload
- Uses pay-as-you-go pricing so you only pay for actual code executions
- Provides a simple API to integrate code execution into any application