To do that you have to own VPS to run shell commands the following example shows you how to run a python file in shell. That means you will receive the input then create a virtual file with python name and then execute it by using the following command.
python3 file_name.py
Once you finished the compilation, you have to delete the virtual file to save the memory and clean caches.
That’s the idea.
There are many sites such as (W3schools, Programiz, Sitepoint , CodedTag) using an online compiler like online python compiler, node.js compiler, etc.
I think all these sites are using the same idea.