This is just a fun little toy I had been playing around with. After some testing it appears as though you can convert a bytes-like object variable directly into an executable shellcode buffer. This can be done by getting the variable's memory location with the id() function and then adding 32 bytes of offset to account for the PyObject header.
After that, it's as simple as adjusting the memory permissions (VirtualProtect) and running with the method of your choice. This example uses a cast to CFUNCTYPE and spawning it off as a thread.
I've tested it on python 3.10-3.12, some are more forgiving than others and some shellcodes don't work. Was still a fun little project to tinker with.