Skip to content

emuly proxy and emuly dev: phone traffic and adb through your computer - #48

Merged
codewarnab merged 12 commits into
mainfrom
emuly-dev
Nov 25, 2026
Merged

codewarnab merged 12 commits into
mainfrom
emuly-dev

Conversation

@codewarnab

Copy link
Copy Markdown
Owner

What this adds

Two new CLI commands for working with a phone from your own computer.

emuly proxy <phone>: phone traffic through your computer

All traffic of the phone leaves from your computer, or from a proxy that you name. Use it to test from your own IP, your office network, or a VPN.

emuly proxy <phone> [--via http://… | socks5://…] [--lock] [--allow-lan]
emuly proxy <phone> status | off
  • All TCP goes through your computer. DNS goes there too. Other UDP is blocked, so apps fall back to TCP. Nothing leaks direct.
  • --via chains to an upstream HTTP or SOCKS5 proxy, with a login. The password stays on your computer. It is never sent to Emuly, written to disk, or printed. EMULY_PROXY_VIA keeps it out of shell history.
  • Your LAN is safe. By default, phone apps cannot reach your computer's localhost or LAN. --allow-lan turns this off.
  • Ctrl-C puts the phone back on its own network. --lock keeps the phone offline instead (fail closed) until emuly proxy <phone> off.
  • If the CLI is killed without --lock, the runner goes back to direct after 90 s, so the phone is not left offline.

emuly dev <phone>: hot reload with local adb

One command connects the phone to adb on your computer, so flutter run, expo run:android and Android Studio see it.

How it works (proxy on)

flowchart LR
  subgraph CS["Codespace"]
    APP["App on the phone"] -->|every TCP connection| GW["Egress gateway<br/>(runner, :8792)"]
    APP -->|DNS| DNS["DNS forwarder<br/>(:53 on 127.0.0.77)"]
    APP -.->|other UDP| X["Blocked"]
  end
  GW -->|CONNECT, over the link| LP["emuly proxy<br/>on your computer"]
  DNS -->|DNS over TCP, same link| LP
  LP --> NET["Internet"]
  LP -.->|--via| UP["Your upstream proxy"] --> NET
Loading
  • The emulator always starts with -http-proxy to the runner gateway. So the mode changes at run time, with no restart.
  • Direct mode (default): the gateway connects out from the codespace. It refuses private and link-local addresses, so an app cannot reach the codespace's own services.
  • Laptop mode: the gateway sends each connection through the link to emuly proxy. If the link is down, the connection fails. It never falls back to direct.
  • 10.0.2.2 links keep working in both modes.

Changes

Area Change
Runner (v23) egress.mjs gateway, egress-dns.mjs forwarder, UDP rules in the phone, GET/POST /egress, POST /egress/check. Mode saved in /workspaces/.emuly/egress.json. Port 8792 reserved.
Boot boot.sh adds -http-proxy and -dns-server.
API GET/POST/DELETE /v1/phones/<id>/proxy, POST /v1/phones/<id>/proxy/check. No credentials reach the API.
CLI emuly proxy, emuly dev. emuly link shares its link loop with proxy.
Dashboard A "Traffic" row in the links panel: via your computer, or blocked when the proxy is offline.
Skill references/tasks/proxy.md, runbook version raised.

Tests

  • Unit tests: gateway modes, address blocking (with NAT64), half-close, mode file, DNS forwarder, local proxy LAN refusal, HTTP and SOCKS5 auth, no password in any output, API input checks.
  • Live test in a codespace: exit IP, DNS, UDP block, Ctrl-C back to direct, fail closed with --lock, auto return to direct without --lock. Details are in docs/phone-proxy-plan.md.
  • pnpm lint, pnpm test, pnpm build pass.

Not tested live yet: Chrome and Flutter on screen, a DNS leak site, a network drop, --via against a real proxy.

One gh codespace ssh carries adb (-L to adbd 5555, compressed) and extra ports (-R). Handles the phone's own codespace, a second run (lock file), adb lookup in SDK folders, WSL, reconnects and API level warnings. Plan and edge cases in docs/emuly-dev-plan.md.
Runner 23: egress gateway on 127.0.0.1:8792 (CONNECT and plain HTTP, direct or laptop mode,
fail closed), DNS forwarder on 127.0.0.77, UDP drop in laptop mode, /egress routes.
CLI: emuly proxy <phone> [--via http|socks5] [--lock] [--allow-lan] | off | status.
API: /v1/phones/<id>/proxy and /proxy/check. Dashboard traffic row. Skill page proxy.md.
Live-tested on a codespace; results in docs/phone-proxy-plan.md.
@vercel

vercel Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
emuly Ignored Ignored Preview Nov 25, 2026 1:22pm UTC

- Drop owner_id and phone_id from diagnostic records. A phone reaches its records
  only through phones.diagnostic_run_id, a random id that changes each phone life.
- Remove the EMULY_DIAGNOSTICS_PHONE filter (server and browser).
- Count write failures by error class (constraint, busy, timeout, schema, other).
- operation() returns its id at once; measure() does not await writes. Writes run in
  the background queue, kept alive with waitUntil on Vercel.
- Test: a 300 ms diagnostics database adds no time to a measured request.
- Every /v1 route is wrapped with withApiUsage. It counts calls by route template,
  client (cli, skill, browser, curl), auth kind, status class, error code and a time
  bucket, per UTC day. No user, phone, key, IP or real path is stored.
- Pattern counts: retry_same_route, poll_after_wait, screenshot_burst, unknown_route,
  old_client. The detector window lives in memory only.
- Counts flush in one background batch (waitUntil on Vercel). A request never waits.
- The CLI sends X-Emuly-Client: cli. Report: scripts/diagnostics.ts ... api
  (groups under 10 samples hidden). Counts live 180 days.
- diagnostic_states (migration 30): day, release, from/to state, reason, error code, region, power-of-2 bucket. No ids.
- lib/diagnostics/state-usage.ts: non-blocking recorder, fixed error codes, states report (10-sample minimum).
- Recorded at each state change in phone-mutations.ts; poller and reconcile go through apply().
- New error codes: github_quota, github_auth, kvm_missing, boot_timeout, runner_crash, tunnel_lost.
- Retention 180 days. Tests: anonymity, counts, report threshold, slow database.
- Phone page: one 'Internet' row ('Through your computer' / 'Paused, reconnecting'), details behind an info icon.
  The proxy's own port row is hidden. More space under the Host row.
- Runner 24: an unlocked laptop proxy with no laptop for 2 minutes goes back to direct.
  Live test found that a killed CLI or a sleeping laptop left the phone offline until 'emuly proxy off'.
- Skill: says what happens when the computer drops (runbook 2026-11-25.3).
@codewarnab
codewarnab merged commit d7de32c into main Nov 25, 2026
6 checks passed
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.

1 participant