-
Notifications
You must be signed in to change notification settings - Fork 500
Description
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.
- [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-Browser bridge and SSH Agent support.
# Author: Xande (CachyOS / Distrobox user)
# 1. Variables (Customize these!)
NAME="dev-github"
HOME_DIR="$HOME/containers/$NAME"
USER_UID=$(id -u)
echo "✈️ Preparing FlyBridge container: $NAME..."
mkdir -p "$HOME_DIR"
# 2. Create the Container
# We mount the D-Bus bus and SSH Agent socket to allow host communication.
# Note: Using --additional-packages for initial dependencies.
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 (Fixes the common "Setting up existing user" error on first run)
echo "🔄 Initializing container environment (First-run warm-up)..."
distrobox enter "$NAME" -- /bin/true 2>/dev/null || true
# 4. Entering the container
# We force SHELL=/bin/bash for the first setup to ensure compatibility
echo "🚀 Entering $NAME for configuration..."
SHELL=/bin/bash distrobox enter "$NAME"x enter "$NAME"
- 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
# 1. Clean broken paths to prevent "command not found" errors
sudo rm -f /usr/local/bin/xdg-open
sudo rm -f /usr/local/bin/distrobox-host-exec
# 2. Create the bridge in /usr/local/bin (High Priority Location)
sudo tee /usr/local/bin/xdg-open << 'EOF'
#!/usr/bin/python3
import sys, dbus, os
# Ensure the Host D-Bus is found
os.environ["DBUS_SESSION_BUS_ADDRESS"] = f"unix:path=/run/user/{os.getuid()}/bus"
try:
url = sys.argv[1]
bus = dbus.SessionBus()
obj = bus.get_object("org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop")
iface = dbus.Interface(obj, "org.freedesktop.portal.OpenURI")
iface.OpenURI("", url, {})
except Exception:
pass
EOF
# 3. Set execution permissions
sudo chmod 755 /usr/local/bin/xdg-open
# 4. Create Distrobox integration links
sudo ln -sf /usr/local/bin/xdg-open /usr/local/bin/distrobox-host-exec
# 5. FIX FOR ICONS: Global Variable in /etc/environment
# This ensures that GUI apps (like Antigravity) see the bridge even when opened via the menu
sudo sh -c "echo 'BROWSER=\"/usr/local/bin/xdg-open\"' >> /etc/environment"
# 6. Update PATH for the current terminal session (Bash/Fish/Zsh)
export PATH="/usr/local/bin:$PATH"
export BROWSER="/usr/local/bin/xdg-open"
hash -r 2>/dev/null || true
echo "✅ Setup Finished! Testing..."
xdg-open https://www.google.com
Bash CONTAINER (Bonus)
# --- Bonus: Install Antigravity, Chrome & Export Icon ---
echo "📥 Checking for Antigravity and Dependencies..."
# 1. Install Google Chrome (Required for AI Browser Agents)
if ! command -v google-chrome &> /dev/null; then
echo "🌐 Installing Google Chrome..."
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt update && sudo apt install -y ./google-chrome-stable_current_amd64.deb
rm google-chrome-stable_current_amd64.deb
fi
# 2. Install Antigravity IDE
if ! command -v antigravity &> /dev/null; then
echo "🔑 Configuring Antigravity repo and installing..."
sudo bash -c '
mkdir -p /etc/apt/keyrings
curl -fsSL https://us-central1-apt.pkg.dev/doc/repo-signing-key.gpg | gpg --dearmor --yes -o /etc/apt/keyrings/antigravity-repo-key.gpg
echo "deb [signed-by=/etc/apt/keyrings/antigravity-repo-key.gpg] https://us-central1-apt.pkg.dev/projects/antigravity-auto-updater-dev/ antigravity-debian main" > /etc/apt/sources.list.d/antigravity.list
apt-get update && apt-get install -y antigravity
'
# Export the app icon to the Host OS Menu
distrobox-export --app antigravity
echo "✅ Installed and exported to Host Menu!"
else
echo "✔ Antigravity and Chrome are ready."
fi
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!