Firewall
A firewall is a set of rules that allows or blocks network traffic based on where it comes from, where it goes, and what it carries.
A firewall checks network traffic against a list of rules and lets through only what the rules allow. Rules can match addresses, ports and protocols, and some firewalls also inspect the content. A firewall can run on a dedicated device at the edge of a network or in the kernel of each machine. Linux, for example, filters packets in the kernel with nftables or iptables.
Firewalls reduce what an attacker can reach. A service that is not exposed cannot be attacked directly from outside. The safest rule set starts by denying everything and then allows only the traffic a system needs. Traffic coming in and traffic going out are filtered separately, since each guards against a different risk.
A sandbox platform uses firewalls at several layers. Rules on each host keep a sandbox from reaching other sandboxes, the host itself, or internal services. Ingress rules decide which ports of a sandbox the internet can reach, and egress control decides where its code can connect. Firewalls limit the damage that code inside a sandbox can do, but they are one layer among several, not a complete defense.