# Task for an AI agent: run Codex on Linux through a proxy with direct egress blocked

Fill in the values below and give this file to an agent that already has access
to your Linux project server. Also provide the article's
`codex-linux-network-guard-v1-20261129.tar.gz` archive, or its exact location.
Do not put passwords, tokens, device codes, or private SSH keys in this file.

## My values

```text
Project server or existing SSH profile: <FILL IN>
Codex account on Linux: developer
Account home: /home/developer
Development project directory: <ABSOLUTE LINUX PATH>
Fixed IPv4 address of the HTTP proxy: <FILL IN>
HTTP CONNECT proxy port: <FILL IN>
Proxy access: allowlist the project server's outbound public IP
Expected proxy exit IPv4: <FILL IN, OR WRITE UNKNOWN>
Source archive: <ATTACHED, OR GIVE ABSOLUTE FILE PATH>
Existing administrator access method: <DESCRIBE WITHOUT SECRETS>
```

If the proxy uses username and password authentication, ask for a private way to
configure it. Do not request credentials in chat. This task assumes HTTP CONNECT
with source IP authorization. A SOCKS5 endpoint, proxy hostname, rotating IP, or
different authentication method needs an explicit adaptation.

## Outcome

Configure the Linux part of the guide, steps 3–5: proxy routing for Codex,
network filters that block direct connections, and checks performed on this
server. Reuse an existing Codex installation when it works under the intended
ordinary account. Install Codex only if it is absent. Finally, help me sign in
without handling my credentials. Explain each change and its purpose plainly.

Work on the project server. The overseas VPS already provides the proxy.
Windows VPN rules and the SSH connection in the ChatGPT desktop app are separate.
SSH access from Windows does not transfer the Windows VPN to Linux.

Begin with read-only inspection. Show the exact files, packages, account,
privileges, test plan, and rollback before changing the server. Continue within
this task after the plan. Request information only when required values are
missing. If a current Codex launcher or running task conflicts with the proposed
change, explain the conflict and agree on the switch before touching it.

## Source files

Use the supplied archive; do not invent replacement filter code. Its SHA-256 is:

```text
e7d1153b26841df27f712bc7e18129f142f38c189bf16d90bc35e32c1b545b68
```

It contains exactly 11 regular files: `README_RU.md`, `README_EN.md`, `codex`,
`codex-guard-enter`, `codex-guard-load`, `codex-guard-probe`, `codex-guard-run`,
`codex-guard-verify`, `codex-guard.sudoers.example`, `guard.bpf.c`, and
`packet_probes.py`. Check the archive hash, file list, paths, and absence of
links before extraction. Read `README_EN.md` and all privileged scripts before
running them. A matching hash identifies this version; it does not replace code
review. Stop if the archive differs.

Production article and archive URLs:

- https://frigate-proxy.ru/en/blog/codex-server-chatgpt-windows-ssh-linux-proxy
- https://frigate-proxy.ru/static/downloads/codex-linux-network-guard-v1-20261129.tar.gz

If those URLs are not yet available, use the attached archive. This task must
be usable with the archive without access to the article.

## 1. Inspect the server and current Codex installation

Identify the actual server, account, OS, kernel, and architecture. Check
systemd 249 or newer, cgroup v2, and available cgroup BPF support. Check Bash,
Python 3, curl, Node.js, npm, clang, gcc, libbpf, jq, bpftool, sudo, and setpriv.
Verify hard-coded system paths used by the supplied scripts. `cgroup2` at
`/sys/fs/cgroup` is a prerequisite, not proof that the filters loaded.

The reference was tested on Ubuntu 22.04.5, kernel 5.15, systemd 249, Node.js
22.23.5, and Codex CLI 0.160.0. You do not need to install those exact versions.
Check compatibility on this host. If the VPS or container cannot attach BPF,
stop and explain the obstacle; proxy environment variables alone do not enforce
the required network boundary.

The intended account must be a normal user with its own home and access to the
development project. The supplied helper requires UID 1000 or higher. Do not
grant unrestricted sudo, change ownership of an entire live website, or add the
user to privileged groups for convenience. Include account creation in the plan
if the account does not exist.

Determine what `codex` resolves to in this user's login shell: executable,
symlink, alias, launcher, version, and installation path. Inspect related sudo
rules, active scopes, and pinned BPF objects without printing secrets. Preserve
the ownership, modes, and content of files you may change in a private backup.

**If Codex is already installed and works for this account, do not reinstall or
upgrade it.** Locate its real executable and verify that it works after the
launcher drops privileges. If the current launcher already routes through the
chosen proxy, attaches both required filters, and checks their actual IDs, keep
it and validate it. Otherwise add only the missing pieces after assessing any
conflict. A different version alone is not a reason to reinstall.

Pay particular attention to `/usr/local/bin/codex`,
`/usr/local/lib/codex-guard`, `/etc/sudoers.d/codex-guard`, and
`/sys/fs/bpf/codex-guide-v1`. The supplied loader reuses an existing pinned BPF
object; replacing a `.o` file on disk does not replace an already loaded object.
Do not infer policy from a matching name. Prepare a coordinated migration if
any of these paths already belongs to another installation. Do not delete
other BPF objects or stop active scopes.

If you are yourself running through the Codex installation being changed,
maintain independent administrator access and avoid interrupting this session.

## 2. Configure and test the HTTP proxy

Use the supplied fixed numeric proxy IPv4 and TCP port. `203.0.113.10:3128` in
the archive is a documentation example and cannot be used as a real endpoint.
For IP authorization, allowlist the project server's actual public outbound IP,
accounting for NAT. It is not the Windows PC address. Do not make the proxy open
to everyone; if the allowlist is not ready, tell me what must be configured.

As the ordinary Codex user, create `~/.config/codex-network` with mode 0700 and
`proxy.env` with mode 0600. Use this setting with the real values substituted:

```sh
CODEX_PROXY_URL='http://<PROXY_IPV4>:<PORT>'
```

Escape user-supplied text correctly when writing the shell file. Keep secrets
out of shell history, repositories, screenshots, and reports. Password-based
proxy access requires adapting npm and probes so credentials do not appear in
process arguments.

Test the proxy before installing Codex or changing its launcher:

```sh
. "$HOME/.config/codex-network/proxy.env"
curl --fail --silent --show-error --max-time 20 --noproxy "" --proxy "$CODEX_PROXY_URL" https://api.ipify.org
printf '\n'
```

Record the returned IPv4 and compare it with the expected exit IP, if known.
If the expected address is unknown, report the observed IP as unconfirmed until
independently matched to the intended VPS. Resolve HTTP 407, timeout, and TLS
errors before continuing. Do not disable TLS certificate checks. Here
`http://` names the HTTP proxy; HTTPS requests travel through CONNECT.

## 3. Reuse or install Codex and prepare its inner launcher

If a suitable Codex is already installed, **skip npm and preserve its version**.
Record the real executable path and check it in the ordinary account's clean
environment. An interactive shell alias or Node.js installed only through
interactive nvm may not be available through SSH in the desktop app. Include
any necessary adaptation in the plan and preserve a rollback.

Only if Codex is absent, install the official `@openai/codex` package as the
ordinary user through the verified proxy into `~/.local/share/codex-cli`:

```sh
. "$HOME/.config/codex-network/proxy.env"
npm --proxy "$CODEX_PROXY_URL" --https-proxy "$CODEX_PROXY_URL" install --global --prefix "$HOME/.local/share/codex-cli" @openai/codex
```

Keep an existing correct inner proxy launcher. Otherwise create
`~/.local/libexec` with mode 0700 and `~/.local/libexec/codex-proxy` owned by
the ordinary user with mode 0700. For the new installation, use:

```sh
#!/bin/sh
set -eu
. "$HOME/.config/codex-network/proxy.env"
: "${CODEX_PROXY_URL:?Set CODEX_PROXY_URL in proxy.env}"
case "$CODEX_PROXY_URL" in
  http://*|https://*) ;;
  *) echo 'Use an HTTP CONNECT proxy URL' >&2; exit 1 ;;
esac
export HTTP_PROXY="$CODEX_PROXY_URL" HTTPS_PROXY="$CODEX_PROXY_URL"
export http_proxy="$CODEX_PROXY_URL" https_proxy="$CODEX_PROXY_URL"
export ALL_PROXY="$CODEX_PROXY_URL" all_proxy="$CODEX_PROXY_URL"
export WS_PROXY="$CODEX_PROXY_URL" WSS_PROXY="$CODEX_PROXY_URL"
export ws_proxy="$CODEX_PROXY_URL" wss_proxy="$CODEX_PROXY_URL"
export NO_PROXY='localhost,127.0.0.1,::1'
export no_proxy="$NO_PROXY"
exec "$HOME/.local/share/codex-cli/bin/codex" "$@"
```

For an existing installation, change the last line to the discovered real
executable. Verify that it is executable after privileges are dropped and does
not point back to this script or the future outer `/usr/local/bin/codex`; that
would create a launch loop. If the real executable currently occupies the
outer command's path, plan an explicit migration to another path, test it, and
preserve the original before switching. Pass all arguments using `"$@"`.

The inner launcher only sets proxy environment variables. It must not become
the public `codex` command or be used for account login before the protected
outer command is installed. Do not set these variables globally for the entire
website or server. Node.js must be available after privilege reset, not only
in an interactive nvm session.

## 4. Build and install the network filters

Work from a reviewed archive copy in an administrator-owned directory. Record
every adaptation. In `guard.bpf.c`, set `PROXY_IPV4` and `PROXY_PORT` to the
same endpoint used in `proxy.env`. Convert IPv4 with
`ipaddress.IPv4Address` to a hexadecimal integer and retain the C `u` suffix.
The filter compares packet addresses, so a proxy hostname is unsuitable.

If the account differs from `developer`, update together the `SUDO_USER` check
in `codex-guard-run`, the account and home checks in `codex-guard-enter`, and
the sudoers entry. Review every occurrence; do not perform an indiscriminate
search and replace. Verify system paths on this distribution and install only
necessary packages from trusted sources. On Ubuntu,
`linux-tools-$(uname -r)` must match the running kernel.

Build two objects from the reviewed `guard.bpf.c`:

```sh
clang -O2 -g -target bpf -I "/usr/include/$(gcc -dumpmachine)" -c guard.bpf.c -o egress.bpf.o
clang -O2 -g -target bpf -I "/usr/include/$(gcc -dumpmachine)" -DFILTER_INGRESS -c guard.bpf.c -o ingress.bpf.o
```

The example allows TCP to the selected external proxy and replies from it,
plus local TCP to `127.0.0.1:8118` and `[::1]:8118` with replies. Other direct
external TCP, UDP/DNS, external IPv6, other local TCP ports, and new incoming
SYN packets without ACK are blocked for the protected group. This is packet
filtering by peer, port, and flags, not stateful conntrack.

The local port 8118 is a real exception. Check whether anything listens there
and where it forwards traffic. If its route is unknown or bypasses the chosen
proxy, report the issue and propose a narrow change with repeated tests. Do not
stop a shared service or install Privoxy automatically: a ready HTTP proxy does
not need it.

After checking existing paths and unexpected symlinks, install the following
files with these owners and modes. Preserve correctly configured shared
directories and any compatible existing protected launcher.

| Files | Destination | Owner | Mode |
| --- | --- | --- | --- |
| `egress.bpf.o`, `ingress.bpf.o`, `packet_probes.py` | `/usr/local/lib/codex-guard/` | root:root | 0644 |
| `codex-guard-load`, `codex-guard-run` | `/usr/local/sbin/` | root:root | 0755 |
| `codex-guard-enter`, `codex-guard-verify`, `codex-guard-probe` | `/usr/local/libexec/` | root:root | 0755 |
| Outer `codex`, if a new protected launcher is needed | `/usr/local/bin/codex` | root:root | 0755 |
| Adapted sudoers entry | `/etc/sudoers.d/codex-guard` | root:root | 0440 |

Directories must be root-owned and not writable by the Codex user. Do not
overwrite an existing launcher without a coordinated switch.

Replace `your_command_here` in `codex-guard.sudoers.example` only with
`/usr/local/sbin/codex-guard-run`. First validate the candidate using
`visudo -cf`, then install it and run `visudo -c`. Do not grant arbitrary root
shell, `systemd-run`, rule-editing privileges, or unrestricted sudo.

Preserve the archive's launch sequence: outer `codex` calls the fixed helper;
the helper loads filters and creates a systemd scope; inside it, the actual
attached IDs of both programs are checked; then `setpriv` drops privileges and
starts the inner `codex-proxy`. Codex runs under the ordinary account without
capabilities, with `NoNewPrivs`, and receives all original arguments via `"$@"`.

An empty bpftool response, invalid JSON, missing filter, or mismatched ID must
stop startup before Codex runs. Preserve the `jq -s` check requiring exactly
one array containing both attached programs. A `BPFProgram=` configuration
line by itself is insufficient evidence that a program was attached.

## 5. Test protection on this server

The README's test results describe the author's test guest. Report only tests
actually performed here, with command, exit status, and observed result. Use
separate temporary scopes with both programs attached and verification inside
the group. The loader is `/usr/local/sbin/codex-guard-load`.

```sh
sudo systemd-run --scope --quiet --collect \
  --property=BPFProgram=egress:/sys/fs/bpf/codex-guide-v1/egress \
  --property=BPFProgram=ingress:/sys/fs/bpf/codex-guide-v1/ingress \
  -- /usr/local/libexec/codex-guard-probe <MODE> <ARGUMENT_IF_NEEDED>
```

The template's mode is `proxy`, `direct`, `dns`, or `ipv6`. Only `proxy` takes
an additional argument: the verified proxy URL without credentials. Use any
coordinated new paths if the existing installation required migration.

Check these outcomes:

- **Proxy:** the request returns the expected external IPv4.
- **Direct IPv4 TCP:** blocked. `No direct connection:` is the expected probe
  output; `FAILED: direct traffic was not blocked` is a failed test.
- **UDP DNS and external IPv6:** blocked from the protected group. Compare with
  known working test destinations outside the protected group using a separate
  administrator diagnostic process. If the control route fails too, record
  “not proven,” rather than claiming filter success. Do not launch Codex
  unprotected for this check.
- **Child process and privilege drop:** an ordinary child keeps the restriction.
  Verify the runtime user, group, capabilities, `NoNewPrivs`, and cgroup after
  privilege drop. Root probes alone do not prove this.
- **Proxy failure:** the protected process cannot fall back to direct access.
  Use an isolated test without stopping a shared live proxy. A wrong test port
  tests that connection, not a real outage of the existing service; report
  precisely which case was tested.
- **Missing or partial attachment:** the helper refuses to run the test
  command if either filter is absent. Use isolated test groups and do not
  detach filters or remove pinned objects used by live Codex tasks.
- **Outer command:** in a fresh SSH session for the intended account,
  `command -v codex` returns `/usr/local/bin/codex`, `codex --version` works,
  and `bash -lc 'command -v codex; codex --version'` resolves the same path.
  Do not substitute the inner `codex-proxy` for this command.

If a direct connection succeeds or startup works without complete filtering,
stop before authentication, fix the cause, and repeat affected checks. Mark
unavailable control routes as a limitation, not a success.

## 6. Guide me through account sign-in

Once the protection checks pass, invite me to run as the ordinary user:

```sh
codex login --device-auth
codex login status
```

I complete the browser sign-in myself. Explain where the URL and one-time code
appear, and wait for me before checking status. Do not send the code elsewhere,
save it in a report, or read/copy `auth.json`. If safe interactive guidance is
unavailable, give me the command for my own terminal.

Device code availability depends on account and workspace settings. If it is
unavailable, consult the official authentication guide and explain the next
step; do not substitute someone else's cached tokens. The Windows browser may
need its own VPN route: a rule for ChatGPT alone does not route the browser.

Successful `login status` proves authentication but does not prove a model
request or its outbound IP. After I sign in, and if permitted in this task,
run a read-only task that lists the development directory's top-level files.
Otherwise provide that task for me to run in the app and mark it untested.

## 7. Report and maintenance

Report the prepared host and ordinary account, project directory, installed
versions, exact protected `codex` path, modified files with owners and modes,
private backup location, and a scoped rollback procedure without exposing
secrets. For each check report “passed,” “failed,” “not run,” or “not proven”:
proxy routing, direct TCP/DNS/IPv6, child processes, missing filters, ordinary
privileges, authentication, and an actual model request. Tell me which actions
remain: sign in, add the SSH profile in ChatGPT, select the folder, and run the
first task. Do not mark them complete without checking.

Explain that pinned BPF objects disappear from memory on reboot. The loader
recreates them from disk and verifies attachment; there is no need to reboot
the server for this task. Do not claim a successful reboot without testing it.
When changing the proxy IP or port, update the proxy settings and both filters
together, test a new launch, then finish old tasks separately. Replacing `.o`
on disk alone does not update a loaded program.

Preserve SSH access, host routes, the shared firewall, and website services.
Do not expose app-server, reset iptables/nftables, weaken Codex sandboxing, or
allow the entire internet on port 443 just to pass a check. If a rollback
returns to an unfiltered launcher, label it accordingly.

This controls the selected Codex launch and its ordinary child processes. It
does not isolate every user process, file, Unix socket, or external cloud tool,
and does not defend against root. Check Windows routing independently.

## References

- Production article: https://frigate-proxy.ru/en/blog/codex-server-chatgpt-windows-ssh-linux-proxy
- Official Codex authentication: https://learn.chatgpt.com/docs/auth
- systemd BPFProgram: https://www.freedesktop.org/software/systemd/man/249/systemd.resource-control.html
- Linux cgroup BPF program types: https://docs.kernel.org/bpf/libbpf/program_types.html

Read this task and the archive, confirm the required values, and begin with
read-only inspection of the specified server.
