How can I view ONLY localhost: pages WITHOUT having to turn off internet?

I need a way to access localhost: pages, so I can view a CLI application with a GUI, and I couldn’t find any application that can do that WITHOUT also being able to view regular internet pages (for security reasons), so I am stuck with Firefox/Librewolf to do that (Unless the alternative I was looking for actually exists, in which case let me know)

I’ve searched in the internet, and the only way I currently know to disable Firefox is to disable network for the firefox flatpak in flatseal, but that also makes Firefox unable to view localhost: pages for some reason, so to view those I have to enable network while running the CLI app. (Using a Virtual Machine for it wouldn’t work since the CLI app uses the GPU, and thus wouldn’t work inside a VM)

Is there a setting somewhere in about:config that does what I am looking for? Or an alternative which only views localhost: pages? (The latter would actually be preferable since I only use firefox for localhost pages

I feel like this is best done with an OS/external firewall rather than in the browser itself, which really depends on your OS. On Linux you could try something like this:

If you wanted to go the VM route you could also make a VM which can only access the host machine, still run the CLI app on the host, but run the browser in that VM.