It is a solved problem - you need to use a build system with sandboxing like Bazel, and also vendor all your tools.
Almost nobody does that because very few people realise it is the solution and even fewer realise they're going to need that before they set up their build system.
Almost nobody does that because very few people realise it is the solution and even fewer realise they're going to need that before they set up their build system.