Java has actually had this built in for a long time now. A SecurityManager allows you to restrict access to things like the filesystem and the network (and whatever else you want). I have never seen it used in a real codebase.
https://docs.oracle.com/javase/tutorial/essential/environmen...