'Control a Virtual Machine completely with callbacks

I want to setup a virtual machine to execute a process in a sandbox. I know that there is libvirt that can create and manage a VM. But what if I want complete control over the VM when its running the process? Such as when its doing disk I/O or memory access. Is there any library which could setup the VM and let me register callbacks to be executed when the process is running, for getting disk and memory bytes? Or when its doing network access?

Ideally what I am looking for is something that would allow registering callbacks like:

byte[] getFileBytes(string filePath, int numBytes)

Similar callbacks for all the OS resources. It would probably be very slow as a normal VM would optimize these things a lot. But it would allow low level control and customization of what the process receives from various resources without having to create virtual disks.

My initial intent is to use it for fully sandboxing Python code.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source