[Discussion] Opening Host Browser links from Distrobox/Docker (for Antigravity login and others)
question
Hi everyone,
I’m sharing a fix for a problem I recently faced. While using a containerized dev environment, I couldn't open any links in my host browser. This was a dealbreaker for tools like Antigravity, where the login process requires opening an OAuth URL in the browser.
I'm using CachyOS as my host with Distrobox + Docker, and this Python-based bridge was the only way I found to reliably "break" the container isolation and trigger the host's default browser.
1. [Optional] "FlyBridge" Container Creation Template
If you are setting up a new container, this is the script I use. It includes a "warm-up" step to avoid the common Setting up existing user error when using custom home directories on external drives.
🚨 Note: Review and customize HOME_DIR and NAME before running.
Bash HOST
```
#!/bin/bash
# --- FlyBridge: Container Creation Template ---
# Purpose: Setup a container with Host-Bus and SSH Agent support.
# 1. Variables (Customize these!)
NAME="dev-ubuntu"
HOME_DIR="$HOME/containers/$NAME"
USER_UID=$(id -u)
echo "✈️ Preparing FlyBridge container: $NAME..."
mkdir -p "$HOME_DIR"
# 2. Create the Container
# IMPORTANT: Mounting the D-Bus bus is mandatory for the browser bridge!
distrobox create -n "$NAME" \
--image ubuntu:latest \
--home "$HOME_DIR" \
--volume /run/user/$USER_UID/bus:/run/user/$USER_UID/bus \
--volume /run/user/$USER_UID/ssh-agent.socket:/run/user/$USER_UID/ssh-agent.socket \
--additional-packages "python3-dbus libpam-ssh-agent-auth sudo git curl"
echo "✅ Container $NAME created successfully!"
# 3. Silent Warm-up
# Triggers initial setup to prevent first-run errors
distrobox enter "$NAME" -- /bin/true 2>/dev/null || true
# 4. Entering the container
echo "🚀 Entering $NAME..."
SHELL=/bin/bash distrobox enter "$NAME"
```
2. The Solution: Host-Browser Bridge (Python)
Once inside the container, run these commands. It replaces the broken xdg-open with a Python script that talks to the host's org.freedesktop.portal.OpenURI interface.
This is what allowed my Antigravity login to finally work.
Bash CONTAINER
```
#!/bin/bash
# 1. Create the local user bin directory
mkdir -p ~/.local/bin
# 2. Create the xdg-open Python bridge script with D-Bus logic
cat << 'EOF' > ~/.local/bin/xdg-open
#!/usr/bin/python3
import sys, dbus, os
# Configure the Host's session bus address
os.environ["DBUS_SESSION_BUS_ADDRESS"] = f"unix:path=/run/user/{os.getuid()}/bus"
try:
bus = dbus.SessionBus()
obj = bus.get_object("org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop")
iface = dbus.Interface(obj, "org.freedesktop.portal.OpenURI")
# Send the URL to the Host (CachyOS)
iface.OpenURI("", sys.argv[1], {})
except Exception as e:
# Silent fallback
pass
EOF
# 3. Grant execution permissions to the script
chmod +x ~/.local/bin/xdg-open
# 4. Add to PATH in .bashrc if not already present
if ! grep -q ".local/bin" ~/.bashrc; then
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
echo "Path added to .bashrc successfully."
fi
# 5. Apply changes to the current environment and clear command hash
export PATH="$HOME/.local/bin:$PATH"
hash -r
# 6. Install necessary Python dependencies
sudo apt update && sudo apt install -y python3-dbus
echo "---------------------------------------------------"
echo "Setup complete!"
echo "Current executable: $(which xdg-open)"
echo "Opening Google on the Host (CachyOS)..."
echo "---------------------------------------------------"
# 7. Test command to open Google
xdg-open https://www.google.com
```
How it solved my issue:
By redirecting the request through the shared D-Bus socket, the container asks the Host OS to handle the link. No browser installation is needed inside the container, and it uses your host's existing cookies and sessions.
Hope this helps anyone else stuck on login screens!
关闭于 2026-01-27 0 条评论