I'd insulated all the bad code in separate processes - a child process of the main program. I.e. for each library runs its own process, where a) the library and b) the communication mechanism with the process of the main program. Nothing more.
Fell child process with a library - Yes, okay.
Need certainly to make the interprocess communication mechanism. But since 24x7, and you can work hard. But then you can live in peace.