Skip to content

Add extra_hosts settings field for resolving internal hostnames#55

Open
adamw wants to merge 1 commit intomasterfrom
extra-hosts
Open

Add extra_hosts settings field for resolving internal hostnames#55
adamw wants to merge 1 commit intomasterfrom
extra-hosts

Conversation

@adamw
Copy link
Copy Markdown
Member

@adamw adamw commented Apr 24, 2026

Maps hostname → IP in settings.json (user/project/local layers, merged with higher precedence winning). The mitmproxy addon writes entries to the shared mitmproxy-config volume, and wg-client appends them to /etc/hosts inside a sentinel block at startup; the agent inherits the file via network_mode: service:wg-client. Resolves #54.

Maps hostname → IP in settings.json (user/project/local layers, merged
with higher precedence winning). The mitmproxy addon writes entries to
the shared mitmproxy-config volume, and wg-client appends them to
/etc/hosts inside a sentinel block at startup; the agent inherits the
file via network_mode: service:wg-client. Resolves #54.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 24, 2026 08:48
lines.append(f"{address}\t{name}")
with open(EXTRA_HOSTS_PATH, "w") as f:
if lines:
f.write("\n".join(lines) + "\n")
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for resolving internal (non-public-DNS) hostnames inside the Sandcat sandbox by introducing an extra_hosts settings field that is merged across settings layers and applied at runtime via /etc/hosts.

Changes:

  • Add extra_hosts to settings merge semantics and document it in the root README.
  • Extend the mitmproxy addon to validate and write extra_hosts mappings into the shared mitmproxy-config volume.
  • Update wg-client init to append the generated mappings into /etc/hosts, and add unit tests covering merge/validation/output format.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
README.md Documents extra_hosts merge rules and how internal hostname resolution works end-to-end.
cli/test/mitmproxy/test_mitmproxy_addon.py Adds tests for extra_hosts merging, validation, and file output format.
cli/templates/devcontainer/sandcat/scripts/wg-client-init.sh Appends shared-volume extra_hosts content into /etc/hosts inside a sentinel block.
cli/templates/devcontainer/sandcat/scripts/mitmproxy_addon.py Implements extra_hosts merge + validation, and writes an /etc/hosts-format file into the shared volume.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +135 to +143
if [ -f "$EXTRA_HOSTS_FILE" ]; then
sed -i '/^# sandcat extra_hosts BEGIN/,/^# sandcat extra_hosts END/d' /etc/hosts
if [ -s "$EXTRA_HOSTS_FILE" ]; then
{
echo "# sandcat extra_hosts BEGIN"
cat "$EXTRA_HOSTS_FILE"
echo "# sandcat extra_hosts END"
} >> /etc/hosts
fi
Comment on lines 61 to +65
self.env = merged["env"]
self._load_secrets(merged["secrets"])
self._load_network_rules(merged["network"])
self._write_placeholders_env()
self._write_extra_hosts(merged["extra_hosts"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DNS lookup base on /etc/hosts file on host computer

3 participants