As above, it cuts both ways.
It is actually beneficial for security that the built-in APIs are made available from a mutable global. This allows consumers to libraries to deny access to APIs, removing them or replacing them from the global before evaluating 3rd party code within that realm.
If the language was changed so that a library could guarantee access to all global APIs this would also give more power to compromised libraries.
Also as above, it's a joint responsibility. A JS library can do as much as it can to maintain the level of robustness that it was first evaluated in. But to achieve 100% confidence the consumer of the library needs to also ensure they are validating their dependencies and sitting up correct sandboxes for untrusted code.
I think many of us would like to see more adoption of the security tooling that exists in this space and there are proposals such as "Compartments" that will make it easier to create sandboxes around modules - scoping their access to global APIs. Though, similar to proxies, these will be more advanced APIs which will only work correctly when used correctly. So applications will need to ensure they use good libraries and tooling that make composing these libraries together more ergonomic.