How to create a virtual machine programmatically?

I’m trying to find a way to run .exe application in python (I mean making virtual box where you can run .exe programs). And when you run the application its will only affect the folder where python script is.

Answer

Dockerfile

FROM python:3
ADD main.py .
ADD the.exe
CMD [ "python", "main.py"]

main.py

import os
os.startfile("/the.exe")

Build

docker build -t isolatedExe:latest .

Run

docker run isolatedExe:latest

Next interact with the container by using

docker exec -i -t <image> /bin/bash

Note: Find the image id with docker ps