'Browser from Windows Sandbox cannot access localhost

I'm running a webserver on my Windows machine on port 4200. If I open a browser, I can communicate with that webserver by going to localhost:4200

I'd like to connect to the webserver from within the Windows Sandbox. My sandbox configuration allows for networking, and a browser in the Sandbox can browse the internet just fine. However, it cannot reach my webserver by going to localhost:4200. I assume this is because localhost refers to the Sandbox itself.

Here is my wsb configuration. Again, internet access works.

<Configuration>
<MappedFolders>
   <MappedFolder>
     <HostFolder>C:\Users\JohnDoe\Documents\Sandbox\Share</HostFolder>
     <ReadOnly>false</ReadOnly>
   </MappedFolder>
</MappedFolders>
</Configuration>

How can I reach my webserver on the host machine from my browser in the sandbox?



Solution 1:[1]

Sandbox localhost is different than your host. Get the "Ethernet adapter vEthernet (Default Switch):" IPv4 Address from host and use it in your sandbox browser

Ex: From within sandbox, I can ping the host:

Pinging 172.20.160.1 with 32 bytes of data:
Reply from 172.20.160.1: bytes=32 time<1ms TTL=128
Reply from 172.20.160.1: bytes=32 time<1ms TTL=128
Reply from 172.20.160.1: bytes=32 time<1ms TTL=128
Reply from 172.20.160.1: bytes=32 time<1ms TTL=128

I could access my localhost app from a sandbox browser by browsing http://172.20.160.1:<app_port>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 vikas