I can provide 2 ways to do want you want: a bad way, and a clean way.
Let's talk about the bad way:
If your script is using "the default gateway" of the system, may be, by setting up a dedicated route for your destination used by your script into your system to avoid your script to use the default gateway, may be enough to solve your problem. This is a bad way because not only your script will be impacted, all the traffic generated from your host to that destination will be impacted.
Let's talk about the clean way. I suppose your are running Linux, but I think you may be able to do the same in all OS that are supporting multi-routing tables feature into their kernel.
Here is the summary of the steps you need to do:
- to prepare the second (or third ...) routing table using the ip command and the 'table table_name' option
- to create a rule traffic selector using ip rule using the uidrange option. This option allows you to select the traffic based on the UID of the user.
When you have done these steps, you can test your setup by creating a user account within the range of UID selected into ip-rule command and test your routing setup.
The last step, is to modify your python script by switching your uid to the uid selected in ip-rule, and existing from it when you have finish to generate your traffic.
To summarize the clean way, it is to do the same as the bad way, but just for a limited number of users uid of your Linux system by using the multi-routing tables kernel feature, and to switch to the selected user into your script to use the special routing setup.
The multi-routing tables feature of kernel is the only feature I think that is able to merge 2 different systems, as you requested it, your host and its VM, without the need of VM. And you can activate the feature by switching from one user to another one into your script of any language.