Doing this kind of thing at the library level is generally not very useful, because security protections between things running in the same process are hard to make very strong.
This is a limitation of the particular language/ecosystem though, it feasible in a new language that has this security baked in to the language primitives.