Suppose I have a script written in Python or Ruby, or a program written in C. How do I ensure that the script has no access to network capabilities?
Firewalls can block specific applications or processes from accessing the network.  ZoneAlarms is a good one that I have used to do exactly what you want in the past.  So it can be done programatically, but I don't know near enough about OS programming to offer any advice on how to go about doing it.
How do I block all network access for a script?