How-To Guides

How to Set Up OpenAI Codex CLI on Windows with PowerShell: Step-by-Step Guide

A step-by-step guide to setting up OpenAI's Codex CLI natively on Windows with PowerShell, VS Code, Git, and GitHub CLI. Go from a Windows machine to running AI-assisted code in under an hour, with no WSL required.

  • Codex runs natively in PowerShell with its own Windows sandbox, no WSL needed
  • The standalone PowerShell installer is the primary install path, with npm as a fallback
  • ️ Know which Windows sandbox you are on, and when a one-time admin approval is needed
  • AGENTS.md gives Codex the same project-rule context that CLAUDE.md gives Claude Code
By Rejith Krishnan29 min read
How to Set Up OpenAI Codex CLI on Windows with PowerShell: Step-by-Step Guide

Why Native Windows Is a Good Foundation for Codex

OpenAI's Windows documentation says to use the native Windows sandbox by default. You install Codex in PowerShell, run it against projects on your normal Windows drive, and keep using the Windows tools you already have. There is no Linux distribution to install and no second filesystem to manage.

Codex enforces its sandbox on Windows itself. The sandbox applies the active filesystem and network permissions to every command Codex runs and to the child processes those commands start. Approval policy is a separate control: it decides when Codex stops to ask before using more access.

Choose WSL instead when you need Linux-native tooling, when your repositories and workflow already live in WSL2, or when the native sandbox options do not fit your machine. We cover that route in our Codex CLI on Windows with WSL guide.

By the end of this guide you will have:

  • VS Code on Windows, configured to open into PowerShell by default
  • Git and GitHub CLI installed with winget and authenticated to your GitHub account
  • Codex CLI installed, verified, signed in, and used to build a Hello World web app
  • A permanent PATH, so every tool works in a fresh PowerShell window without manual fixes
  • An understanding of which Windows sandbox Codex is using on your machine
  • An npm fallback path for teams that standardize on Node.js

Total time: under an hour on a modern machine with a decent connection.

This is the PowerShell companion to our WSL guide, so Steps 1 to 5 follow the same order and the two read as a set.


Prerequisites

  • Windows 11 (recommended), a recent, fully updated Windows 10 (best effort; Windows 10 version 1809 or later), or Windows Server 2019 or later (see Installing on Windows Server below)
  • winget available. If winget --version fails in PowerShell, update Windows or install the Windows Package Manager first. Windows Server 2019 and 2022 ship without winget, so use the official installers in Installing on Windows Server below instead
  • Windows Server users: run every install and PATH step as the account that will actually use Codex. npm packages and the User PATH are per-account
  • Permission to approve one administrator prompt, in case Codex needs to set up its sandbox
  • A ChatGPT plan that includes Codex, or an OpenAI API key
  • A GitHub account (skip Step 4 if you already have one, or create one there in a few minutes)

Check winget now:

winget --version

Installing on Windows Server

On a Windows 10 or Windows 11 workstation, skip this section and go to Step 1.

OpenAI's Windows documentation covers Windows 11 and Windows 10, and does not list Windows Server editions. Codex depends on the modern Windows console (ConPTY), which arrived in Windows 10 version 1809. Windows Server 2019 and later are built on that release or newer, so they meet the same baseline. Treat Windows Server as best effort and try it on a non-production server first.

Check which version you have:

(Get-CimInstance Win32_OperatingSystem).Caption
[System.Environment]::OSVersion.Version
Windows Server Build Same base as Codex in PowerShell
2016 14393 Windows 10 1607 Not supported. It predates ConPTY. Use a newer server or a workstation
2019 17763 Windows 10 1809 Supported, best effort. No winget, so install prerequisites below
2022 20348 Windows Server 21H2 Supported, best effort. No winget, so install prerequisites below
2025 26100 Windows 11 24H2 Supported, best effort. winget is included, so follow the normal steps

Follow Steps 1 to 7 as written, with these changes.

1. Install as the account that will use Codex. The standalone installer puts Codex in the current account's profile (%LOCALAPPDATA%\Programs\OpenAI\Codex\bin) and adds that folder to the current account's User PATH. If you run it as a different administrator account, or as SYSTEM, codex will not exist for anyone else. On a server shared over Remote Desktop, each person installs Codex for their own account. Only the machine-wide prerequisites (Git, GitHub CLI, Node.js) need an administrator.

2. Enable TLS 1.2 before downloading anything. Windows PowerShell 5.1 on older servers can default to protocols that GitHub and nodejs.org reject, which makes downloads fail with "Could not create SSL/TLS secure channel". Run this at the start of each PowerShell window that downloads files:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

3. No winget? Install the prerequisites from the official installers. On Windows Server 2019 and 2022 (and on Server Core, where winget does not run), use this instead of the winget install commands in Steps 1, 5, and 6b. Run it in an administrator PowerShell window. It downloads the latest Git for Windows, GitHub CLI, and Node.js LTS releases and installs them silently for all users:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$ProgressPreference = 'SilentlyContinue'   # much faster downloads in PowerShell 5.1
$dl = Join-Path $env:TEMP 'codex-prereqs'
New-Item -ItemType Directory -Force -Path $dl | Out-Null

# Git for Windows (64-bit)
$git = (Invoke-RestMethod 'https://api.github.com/repos/git-for-windows/git/releases/latest').assets |
    Where-Object name -like 'Git-*-64-bit.exe' | Select-Object -First 1
Invoke-WebRequest $git.browser_download_url -OutFile (Join-Path $dl $git.name) -UseBasicParsing
Start-Process (Join-Path $dl $git.name) -ArgumentList '/VERYSILENT', '/NORESTART' -Wait

# GitHub CLI
$gh = (Invoke-RestMethod 'https://api.github.com/repos/cli/cli/releases/latest').assets |
    Where-Object name -like 'gh_*_windows_amd64.msi' | Select-Object -First 1
Invoke-WebRequest $gh.browser_download_url -OutFile (Join-Path $dl $gh.name) -UseBasicParsing
Start-Process msiexec.exe -ArgumentList '/i', "`"$(Join-Path $dl $gh.name)`"", '/qn', '/norestart' -Wait

# Node.js LTS (only needed for the npm route in Step 6b)
$lts = ((Invoke-RestMethod 'https://nodejs.org/dist/index.json') | Where-Object lts | Select-Object -First 1).version
$msi = "node-$lts-x64.msi"
Invoke-WebRequest "https://nodejs.org/dist/$lts/$msi" -OutFile (Join-Path $dl $msi) -UseBasicParsing
Start-Process msiexec.exe -ArgumentList '/i', "`"$(Join-Path $dl $msi)`"", '/qn', '/norestart' -Wait

These installers add their folders to the System PATH. Close the administrator window, open a normal PowerShell window as the account that will use Codex, and continue with Step 5a to check that git and gh are recognized. Codex itself does not need Node.js when you use the standalone installer in Step 6a, so you can leave out the Node.js block on that route. VS Code also has a system installer at https://code.visualstudio.com/download if you want it on the server.

4. Sign in with one-time codes instead of the server's browser. Internet Explorer Enhanced Security Configuration, which is on by default on Windows Server, blocks most sign-in pages. Both tools offer a code you can enter from any other device.

For GitHub, run this and choose Login with a web browser. It prints a one-time code and the URL https://github.com/login/device. Open that URL on your laptop or phone and enter the code:

gh auth login

For ChatGPT sign-in, run this instead of codex login:

codex login --device-auth

5. Expect the elevated sandbox. OpenAI documents the recommended mxc sandbox for Windows 11 24H2 and 25H2, and does not cover Windows Server, so on a server Codex normally uses the elevated sandbox. That needs a one-time administrator approval. Setup can fail where Group Policy blocks creating local users or groups, changing firewall rules, or granting sandbox-user logon rights, which is common on domain-joined servers. Local accounts cannot be created on a domain controller at all, so do not run Codex there. If setup is blocked, ask IT to run this from an elevated deployment process, as OpenAI's deployment guide describes:

codex sandbox setup --elevated

Run /status inside Codex to see which sandbox is active.

6. Server Core has no desktop. Skip the VS Code steps (1, 3, and 7) and do everything in PowerShell.


Step 1: Install VS Code

Already have VS Code? Skip to Step 2.

You can install it from https://code.visualstudio.com, or from PowerShell:

winget install --id Microsoft.VisualStudioCode -e

If you use the website installer, run it with the defaults and, on Select Additional Tasks, check Add to PATH so code . works from any terminal. Launch VS Code once so it finishes first-run setup, then close and reopen PowerShell so the PATH change takes effect.

Tip: Pin VS Code to your taskbar. You will open it constantly.


Step 2: Check Your Windows Terminal and Winget Setup

Unlike the WSL route, there is no Linux layer to install here. This step makes sure your shell and package manager are ready.

2a. Open PowerShell

Search for Windows Terminal or PowerShell in the Start menu and open it. A normal (non-admin) window is what you want for everything in this guide, including running Codex. Administrator rights are only needed if Codex asks to set up its sandbox, or if you choose to update the System PATH for all users in Step 6c.

2b. Confirm winget works

winget --version

You should see a version number. If the command is not found, update Windows or install the Windows Package Manager, then reopen PowerShell.

2c. Confirm package IDs before install

winget search --id Microsoft.VisualStudioCode -e
winget search --id Git.Git -e
winget search --id GitHub.cli -e
winget search --id OpenJS.NodeJS.LTS -e

Each command should return one exact match.

2d. Check your Windows version

[System.Environment]::OSVersion.Version

Build 26100 or later means Windows 11 24H2 or newer, which supports Codex's recommended sandbox (more on that in Step 6). Older builds still work using a fallback sandbox.


Step 3: Set PowerShell as the Default Terminal in VS Code

  1. Open VS Code and press Ctrl + Shift + P.
  2. Run Terminal: Select Default Profile.
  3. Select PowerShell.

New terminals (Ctrl + backtick) now open in PowerShell with a prompt like:

PS C:\Users\yourname>

If you see a different shell, such as Command Prompt or Git Bash, repeat the steps.

Tip: Type code . in any folder from PowerShell and VS Code opens that folder.


Step 4: Set Up Your GitHub Account

Already have a GitHub account? Skip to Step 5. Use the same account you use for work or personal projects. There is no need to create a new one.

If you do not have one yet:

  1. Go to https://github.com and create a free account.
  2. Add a profile photo and your name.
  3. Students can apply for the GitHub Student Developer Pack at https://education.github.com/students.

Step 5: Install Git and GitHub CLI

winget install --id Git.Git -e
winget install --id GitHub.cli -e

Close every PowerShell and Windows Terminal window (and VS Code, if it is open), then open a new PowerShell window. New tabs inherit their PATH from the parent Windows Terminal or VS Code process, so opening a new tab is not enough.

5a. Verify Git and GitHub CLI are on PATH

Get-Command git, gh -ErrorAction SilentlyContinue
where.exe git
where.exe gh

Each tool should resolve to a path such as C:\Program Files\Git\cmd\git.exe and C:\Program Files\GitHub CLI\gh.exe.

If PowerShell reports "not recognized" but the files exist on disk, the installer did not update PATH for your session. Run this to fix the current window:

$env:Path += ";$env:ProgramFiles\Git\cmd;$env:ProgramFiles\GitHub CLI"
git --version
gh --version

That change only lasts until you close the window, and it assumes the default install folders. Step 6c makes it permanent and finds the tools on any drive.

If the files do not exist at all, install both again, close every PowerShell window, open a new one, and repeat the check above:

winget install --id Git.Git -e
winget install --id GitHub.cli -e

Without winget, use the installers from https://git-scm.com and https://cli.github.com.

5b. Configure Git and sign in to GitHub

Configure your identity and sign in:

git config --global user.name "Your Name"
git config --global user.email "your-github-email@example.com"
gh auth login

Use the email address already registered to your GitHub account for user.email. If git config --global user.name already returns your correct name, you can skip both git config lines.

At the gh auth login prompts choose GitHub.com, HTTPS, and Login with a web browser. Copy the one-time code, open the URL, paste it, and authorize. Then run:

git --version
gh --version
gh auth status

All three should return versions or a confirmed login with no errors.


Step 6: Install Codex CLI and Build Your First App

Codex is OpenAI's coding agent for the terminal. You describe a task in plain language and it reads, edits, and runs code in your project, asking for approval at the boundaries you set.

6a. Install Codex with the standalone installer (recommended)

Download the PowerShell installer, then run it. The -ExecutionPolicy Bypass flag applies to this one script run only and does not change your system policy:

Invoke-WebRequest -UseBasicParsing -Uri 'https://chatgpt.com/codex/install.ps1' -OutFile '.\codex-install.ps1'
powershell -ExecutionPolicy Bypass -File .\codex-install.ps1

OpenAI's Windows deployment docs confirm this installer defaults to latest when you do not pass -Release. Use -Release only when you need to pin a specific version for managed rollout.

Close and reopen PowerShell, then verify as your normal user, not as administrator:

Get-Command codex
codex --version

Get-Command codex should print a path, and codex --version should print a version number. The installer puts Codex in %LOCALAPPDATA%\Programs\OpenAI\Codex\bin for the current account and adds that folder to your User PATH. If you see "not recognized", confirm you ran the installer in PowerShell (not in a WSL shell) and as this account, then use Step 6c.

You can delete codex-install.ps1 afterward.

6b. Optional fallback: install with npm

Use this path if your team standardizes CLI installs through npm, or if the standalone installer is blocked on your network. The commands below use npm.cmd and codex.cmd instead of npm and codex. On Windows Server, the execution policy often blocks the .ps1 launchers npm creates, while the .cmd launchers always run.

1. Install Node.js LTS with npm.

winget install --id OpenJS.NodeJS.LTS -e --accept-package-agreements --accept-source-agreements

If winget is not available (common on Windows Server 2019 and 2022), download the Windows MSI from https://nodejs.org/en/download and keep the npm package manager and Add to PATH features selected. If Node.js is already installed, repair that installation from Apps > Installed apps rather than installing a second copy.

2. Verify both Node.js and npm. A working node --version does not prove npm is installed, so check both:

Get-Command node, npm.cmd -ErrorAction SilentlyContinue
node --version
npm.cmd --version

If node works but npm.cmd is not found, check whether the npm launcher exists next to Node.js:

$nodeDir = Split-Path (Get-Command node -ErrorAction Stop).Source
Get-ChildItem $nodeDir -Filter 'npm*'
Test-Path (Join-Path $nodeDir 'npm.cmd')

If npm.cmd is missing on disk, no PATH change will fix it. Repair or reinstall Node.js with npm selected. If neither command is recognized but node.exe exists in %ProgramFiles%\nodejs, call it by full path to confirm the install, then fix PATH in Step 6c:

& "$env:ProgramFiles\nodejs\node.exe" --version
& "$env:ProgramFiles\nodejs\npm.cmd" --version

3. Make sure your npm global folder exists. npm installs global packages into a per-user folder, normally %APPDATA%\npm. On Windows Server, this folder is often missing for accounts that have never used npm, and npm fails with an error like this:

npm error code ENOENT
npm error syscall lstat
npm error path C:\Users\yourname\AppData\Roaming\npm

Run the following as the user who will run Codex, not as a different admin account. Check the current prefix first, then create the folder and point npm at it:

npm.cmd config get prefix
$npmPath = Join-Path $env:APPDATA 'npm'
New-Item -ItemType Directory -Path $npmPath -Force | Out-Null
npm.cmd config set prefix "$npmPath"
npm.cmd list -g --depth=0

If config get prefix already shows a different folder your team relies on, create that folder instead of changing the prefix. Never hard-code another user's profile path. Each Windows account has its own npm prefix and its own global packages.

4. Install Codex for the current user.

npm.cmd install -g @openai/codex
npm.cmd list -g --depth=0
$npmPrefix = (npm.cmd config get prefix).Trim()
Test-Path (Join-Path $npmPrefix 'codex.cmd')
& (Join-Path $npmPrefix 'codex.cmd') --version

@openai/codex should appear in the global list and codex.cmd --version should print a version. If Codex was installed under a different Windows account, it will not exist for yours, so install it again here.

6c. Make PATH permanent

This is the most common Windows Server failure: the tools install correctly, but PowerShell still says "the term is not recognized". There are two separate causes, and you usually need to fix both:

  1. The install folder never reached the saved PATH. Windows keeps a saved PATH for the machine (System) and one for each account (User). If an installer did not update them, every new window starts without the tool.
  2. Your terminal is running with an old copy of PATH. Every program gets a copy of PATH when it starts and never sees later changes. A new terminal tab in VS Code or Windows Terminal copies PATH from the VS Code or Windows Terminal process, not from the saved settings. So a tab opened after the fix still fails until you quit the whole app.

The steps below fix the saved PATH, load it into the window you are in, and make sure new sessions pick it up.

1. Paste this helper. It adds a folder to your User PATH (no admin needed). It reads and writes the raw registry value, so entries such as %USERPROFILE%\... stay as they are instead of being turned into fixed paths, and it skips folders that are already there:

function Add-UserPath([string]$Dir) {
    $Dir = $Dir.TrimEnd('\')
    $key = 'HKCU:\Environment'
    $raw = (Get-Item $key).GetValue('Path', '', 'DoNotExpandEnvironmentNames')
    $entries = @($raw -split ';' | Where-Object { $_ })
    $expanded = @($entries | ForEach-Object { [Environment]::ExpandEnvironmentVariables($_).TrimEnd('\') })
    if ($expanded -contains $Dir) { Write-Host "Already on User PATH: $Dir"; return }
    Set-ItemProperty $key -Name Path -Value (($entries + $Dir) -join ';') -Type ExpandString
    [Environment]::SetEnvironmentVariable('CODEX_PATH_REFRESH', $null, 'User')   # tells Windows the environment changed
    Write-Host "Added to User PATH: $Dir"
}

Do not use setx PATH, and do not write PATH with [Environment]::SetEnvironmentVariable('Path', ...). setx truncates PATH at 1,024 characters. SetEnvironmentVariable saves expanded values, which permanently replaces %VAR% entries with fixed paths.

2. Find each tool and add its folder. This block does not assume drive C:. For each tool it checks, in order: the saved System and User PATH, the folder the installer recorded in the registry (Git and Node.js record one), Program Files and Program Files (x86) wherever Windows is installed, your per-user AppData\Local\Programs folder, and Program Files or the root of every local drive (C:, D:, and so on). It only adds a folder when the .exe is actually in it:

$drives = (Get-CimInstance Win32_LogicalDisk -Filter 'DriveType=3').DeviceID   # C:, D:, ...
$roots = @($env:ProgramFiles, ${env:ProgramFiles(x86)}, "$env:LOCALAPPDATA\Programs") +
         @($drives | ForEach-Object { "$_\Program Files", "$_" }) |
         Where-Object { $_ } | Select-Object -Unique
$tools = [ordered]@{
    git   = @{ Exe = 'git.exe';   Sub = 'Git\cmd';          Reg = 'HKLM:\SOFTWARE\GitForWindows'; RegSub = 'cmd' }
    gh    = @{ Exe = 'gh.exe';    Sub = 'GitHub CLI' }
    node  = @{ Exe = 'node.exe';  Sub = 'nodejs';           Reg = 'HKLM:\SOFTWARE\Node.js';       RegSub = '' }
    codex = @{ Exe = 'codex.exe'; Sub = 'OpenAI\Codex\bin' }   # standalone installer
}
$saved = @(([Environment]::GetEnvironmentVariable('Path', 'Machine') + ';' +
            [Environment]::GetEnvironmentVariable('Path', 'User')) -split ';' | Where-Object { $_ })
foreach ($name in $tools.Keys) {
    $t = $tools[$name]
    $already = $saved | Where-Object { Test-Path -LiteralPath "$($_.TrimEnd('\'))\$($t.Exe)" } | Select-Object -First 1
    if ($already) { Write-Host "$name already on saved PATH: $already"; continue }
    $candidates = @()
    if ($t.Reg) {
        $installPath = (Get-ItemProperty $t.Reg -ErrorAction SilentlyContinue).InstallPath
        if ($installPath) { $candidates += "$($installPath.TrimEnd('\'))\$($t.RegSub)".TrimEnd('\') }
    }
    $candidates += $roots | ForEach-Object { "$($_.TrimEnd('\'))\$($t.Sub)" }
    $hit = $candidates | Where-Object { Test-Path -LiteralPath "$_\$($t.Exe)" } | Select-Object -First 1
    if ($hit) { Add-UserPath $hit } else { Write-Warning "$name not found on any local drive" }
}
if (Test-Path "$env:APPDATA\npm") { Add-UserPath "$env:APPDATA\npm" }   # npm route: npm.cmd's global folder

What the warnings mean:

  • git, gh, or node not found on any local drive: the tool is not installed, or it is in a custom folder. Use the three checks below, in order.
  • codex not found: expected on the npm route, where the last line adds npm's global folder (which holds codex.cmd). On the standalone route, re-run the installer in Step 6a as this account, then run the block again.
  • No line for AppData\Roaming\npm: expected if you used only the standalone installer. On the npm route, create the folder with Step 6b, part 3, then run the last line again. If npm.cmd config get prefix shows a different folder, use the custom-folder check below with that folder.

If a tool was not found, check it in this order:

Check A. Is it installed? Run the line for the missing tool (GitHub.cli for gh, OpenJS.NodeJS.LTS for node):

winget list --id Git.Git

If winget does not list it, install it with Step 5 or Step 6b, then run the part 2 block again. A missing node is fine if you used the standalone Codex installer.

Check B. Is it listed but still not found? Search every drive for the real folder. Change git.exe to gh.exe or node.exe as needed:

(Get-CimInstance Win32_LogicalDisk -Filter 'DriveType=3').DeviceID | ForEach-Object { where.exe /R "$_\" git.exe 2>$null }

Check C. Add the folder you found. Replace the path with the folder that holds the .exe (not the .exe itself):

Add-UserPath 'D:\Tools\Git\cmd'

3. Load the saved PATH into this window. The block above changes the saved PATH, not the window you are in, so git still fails here until you run this:

$env:Path = (([Environment]::GetEnvironmentVariable('Path', 'Machine') + ';' +
    [Environment]::GetEnvironmentVariable('Path', 'User')) -split ';' |
    Where-Object { $_ } | Select-Object -Unique) -join ';'

4. Make every new session pick it up, including VS Code. Quit VS Code completely with File > Exit (closing one window is not enough while another VS Code window is open), and close every Windows Terminal window. When they start again they read the saved PATH.

5. Only if a terminal still starts with an old PATH (or you cannot restart VS Code right now), add a PowerShell profile line. This rebuilds PATH from the saved settings in every new PowerShell session. Skip this part if part 4 fixed it:

$p = $PROFILE.CurrentUserAllHosts
if (-not (Test-Path $p)) { New-Item -ItemType File -Path $p -Force | Out-Null }
if (-not (Select-String -Path $p -SimpleMatch 'Rebuild PATH from saved settings' -Quiet)) {
    Add-Content -Path $p -Value @'

# Rebuild PATH from saved settings so new installs work even in a stale VS Code terminal
$env:Path = (([Environment]::GetEnvironmentVariable('Path', 'Machine') + ';' +
    [Environment]::GetEnvironmentVariable('Path', 'User')) -split ';' |
    Where-Object { $_ } | Select-Object -Unique) -join ';'
'@
}

6. Check that PowerShell is allowed to run your profile. PowerShell only runs a profile if scripts are allowed. Windows 10 and 11 block scripts by default (Windows Server allows local scripts). Run this:

Get-ExecutionPolicy -Scope CurrentUser

If the result is Restricted or Undefined on a workstation, run this next, unless your organization's policy says otherwise:

Set-ExecutionPolicy -Scope CurrentUser RemoteSigned

Any other result (RemoteSigned, Unrestricted, Bypass) needs no change.

7. Repeat for each PowerShell edition you use. Windows PowerShell 5.1 and PowerShell 7 use different profile files. Open the other edition and run the part 5 block and the part 6 check there too.

Permanent fix for all users (System PATH, admin required). On shared servers, shared install folders such as Git, GitHub CLI, and Node.js can go on the System PATH instead. Run this in an administrator PowerShell window, changing $dir for each folder. Like the helper, it keeps %VAR% entries and avoids empty entries:

$dir = "$env:ProgramFiles\nodejs"
$key = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
$raw = (Get-Item $key).GetValue('Path', '', 'DoNotExpandEnvironmentNames')
$entries = @($raw -split ';' | Where-Object { $_ })
$expanded = @($entries | ForEach-Object { [Environment]::ExpandEnvironmentVariables($_).TrimEnd('\') })
if ($expanded -notcontains $dir.TrimEnd('\')) {
    Set-ItemProperty $key -Name Path -Value (($entries + $dir) -join ';') -Type ExpandString
    [Environment]::SetEnvironmentVariable('CODEX_PATH_REFRESH', $null, 'Machine')   # tells Windows the environment changed
}

Keep the npm prefix (%APPDATA%\npm) on each user's User PATH, never the System PATH. It points to one person's profile, so other accounts cannot use it.

Only need it working in this window? Run this to add the default folders to the current window only. It is gone when the window closes, so still do parts 1 to 4:

$env:Path += ";$env:ProgramFiles\Git\cmd;$env:ProgramFiles\GitHub CLI;$env:ProgramFiles\nodejs;$env:APPDATA\npm"

6d. Verify everything in a fresh PowerShell session

This is the real test. Quit VS Code with File > Exit and close every PowerShell and Windows Terminal window. Then open a brand-new PowerShell window (or reopen VS Code and open a new terminal) and run the commands below without changing $env:Path first:

Get-Command git, gh, node, npm.cmd, codex -ErrorAction SilentlyContinue | Format-Table Name, Source
git --version
gh --version
node --version
npm.cmd --version
codex --version

Every command should print a version. If you used only the standalone installer, node and npm.cmd are optional. If any command fails here, run the block in Step 6c, part 2 again and read its warnings. Do not continue with a temporary $env:Path fix, because it will be gone the next time you open PowerShell.

6e. Sign in before you start your first session

Choose how to authenticate:

codex login

Option 1, ChatGPT sign-in, uses the access included with your plan. Complete the browser flow.

If the browser cannot reach the CLI, run this instead and enter the one-time code:

codex login --device-auth

Option 2, API key, bills your OpenAI Platform account at API rates. Read the key without echoing it, then pipe it in:

$secureKey = Read-Host 'OpenAI API key' -AsSecureString
$plainKey = [System.Net.NetworkCredential]::new('', $secureKey).Password
$plainKey | codex login --with-api-key
Remove-Variable plainKey, secureKey

Never put a key in a repository, an AGENTS.md, a script, or a prompt.

Confirm either method worked:

codex login status

6f. Understand the Windows sandbox

The first time Codex runs commands on Windows, it uses one of three sandbox implementations:

  • mxc is the recommended sandbox on compatible machines (Windows 11 24H2 or 25H2). It uses native process isolation and needs no administrator-approved setup, extra Windows accounts, or firewall rules.
  • elevated is the preferred fallback when mxc is unavailable. It needs a one-time administrator approval. Commands inside the sandbox still run without administrator privileges.
  • unelevated is a weaker fallback for when elevated setup is not possible. It has weaker network isolation.

If Codex shows a Set up Agent sandbox to continue prompt, approve the administrator (UAC) prompt that follows. This setup prompt appears when Codex must provision the legacy elevated sandbox.

To prefer mxc on a compatible machine, or to pin a fallback, add this to $HOME\.codex\config.toml:

[features]
prefer_mxc = true

[windows]
sandbox = "elevated"

Use only the settings you need. sandbox accepts "elevated" or "unelevated". Inside a Codex session, /status and /debug-config show which settings are active.

6g. Build your first app

New-Item -ItemType Directory -Force -Path "$HOME\git\helloworld" | Out-Null
Set-Location "$HOME\git\helloworld"
git init
codex

Codex starts in its default approval mode, so it will ask before doing anything outside the workspace. Type:

Build me a simple Hello World web app with HTML, CSS, and JavaScript. Give it a clean modern look with a centered card, a heading that says 'Hello World', a subtitle with today's date, and a button that shows an alert when clicked. Save everything in this folder.

Approve the file writes as they come up. When it finishes, run /quit.

6h. Preview your app

From the same folder in PowerShell:

Start-Process .\index.html

Your default browser opens the page.

6i. Keep Codex updated

Run this command in a normal PowerShell window:

codex update

Step 7: Open Your Project in VS Code

Set-Location "$HOME\git"
code .

VS Code opens with your git folder, and Explorer shows helloworld with the files Codex created. The integrated terminal opens in PowerShell, so you can edit, test, and commit without leaving the editor.


Optional: Install Python Without the Installer

Codex does not need Python to run. But Codex often runs Python scripts and tools inside your projects, and the standard Python installer can be blocked on locked-down machines by administrator rights, MSI rules, or AppLocker. The official embeddable ZIP avoids all three. It is a plain archive that you extract into a folder you own.

Skip this section if python --version already works, or if your projects do not use Python.

What you get, and what you do not

  • It runs python.exe directly from the folder. No installer runs and no administrator rights are needed.
  • It does not change PATH unless you ask it to.
  • It does not include pip. The embeddable distribution excludes it and uses isolated module paths, so it differs from a full development installation. For projects that need pip install, use the standard installer if your policy allows it.

Download, verify, and extract

Download the 64-bit embeddable package from the Python downloads page at https://www.python.org/downloads/windows/, or run the commands below. This example uses Python 3.13.17. If you pick a newer release, change $version and copy the matching SHA-256 value from that release's page:

$version = '3.13.17'
$sha256  = '9e35319bffedab8b36ad44d8f377cb4f1733bcec257a0b6d04d94f01486ddb38'
$zip     = Join-Path $env:TEMP "python-$version-embed-amd64.zip"
Invoke-WebRequest -UseBasicParsing -Uri "https://www.python.org/ftp/python/$version/python-$version-embed-amd64.zip" -OutFile $zip

Check the checksum before you extract anything. The two values must match:

(Get-FileHash $zip -Algorithm SHA256).Hash.ToLower() -eq $sha256

If the result is False, delete the file and download it again. Do not extract it.

Extract it into a folder inside your user profile, where you have full read and write permissions:

$pyDir = "$env:LOCALAPPDATA\Programs\Python\Python313-embed"
Expand-Archive -Path $zip -DestinationPath $pyDir -Force
Remove-Item $zip

Verify it runs

& "$env:LOCALAPPDATA\Programs\Python\Python313-embed\python.exe" --version

It should print Python 3.13.17.

Optional: make python work from any window

By default you call Python by its full path, which keeps it isolated from everything else on the machine. If you want to type python instead, add the folder to your User PATH with the Add-UserPath helper from Step 6c, part 1, then load the saved PATH into this window with Step 6c, part 3:

Add-UserPath "$env:LOCALAPPDATA\Programs\Python\Python313-embed"

Best Practices for AI-Assisted Development

Keep projects in a normal folder in your user profile. A path such as C:\Users\yourname\git\my-app works well. Do not move a repository after Codex has set up its sandbox for it, because sandboxing can stop working after a move. If that happens, restart Codex or re-run the sandbox setup.

Watch for the "writable by Everyone" warning. Codex warns when a folder is writable by the Everyone group. Remove that access where appropriate, then restart Codex or re-run the sandbox setup.

Match the approval mode to the risk. Sandbox mode sets what Codex is allowed to touch. Approval policy sets when it must ask. Two settings cover most work:

# Normal development: edit inside the workspace, ask before crossing it
codex --sandbox workspace-write --ask-for-approval on-request

# Investigation and review: no edits
codex --sandbox read-only --ask-for-approval on-request

You can also switch mid-session with /permissions.

Know when full access is fine and when it is not. Full access (--yolo, or --dangerously-bypass-approvals-and-sandbox) means Codex is not limited to your project directory and might perform unintentional destructive actions. It is reasonable in a disposable environment you can throw away, such as a scratch VM or a throwaway learning project. It is the wrong choice on a shared repository, a codebase with credentials nearby, or anything you cannot rebuild. For those, stay on workspace-write with on-request approval so you keep oversight.

--full-auto is not a current Codex flag in codex --help (verified with Codex CLI 0.139.0 on November 1, 2026), so do not rely on it in scripts.

Use /plan before non-trivial changes. Type /plan followed by your request. Codex investigates and proposes an approach without implementing it. Reviewing the plan takes a minute and prevents unwanted changes. Entering Plan mode does not grant write access, and permissions are a separate setting.

Use AGENTS.md as the counterpart to CLAUDE.md. Run /init inside Codex to create a starter AGENTS.md, then edit it. Record build and test commands, conventions, and what Codex must not change. Commit it so the whole team shares the rules. Keep it short, because those tokens load on every task. If your team also uses Claude Code, the same facts belong in both files.

Keep sessions short. Every file read, test log, and message consumes context. Run /status to see usage, /compact to summarize earlier conversation, and /new when the next job is unrelated. Small, focused sessions beat marathon ones. Restate any critical constraint after a compact.

Review before you commit. Run /diff, then /review for a second pass, then run your own tests and check git status.

Check your plan or billing. ChatGPT sign-in follows your plan's limits. API-key sign-in bills per token at platform.openai.com.


Verification Notes

This guide was updated against official docs and CLI help on November 1, 2026:

  • OpenAI Windows deployment docs confirm install.ps1 defaults to latest when -Release is omitted.
  • OpenAI Windows sandbox docs confirm native-Windows default guidance, prefer_mxc, and [windows].sandbox keys.
  • November 3, 2026: added Windows Server guidance from field installs. Covers missing npm.cmd, a missing per-user npm prefix (ENOENT), and install folders that never reach the persistent PATH.
  • November 3, 2026: added Windows Server guidance. OpenAI's Windows sandbox page covers Windows 11 and Windows 10 (ConPTY, version 1809 or later) and does not list Server editions. OpenAI's Windows deployment guide documents the standalone install folder (%LOCALAPPDATA%\Programs\OpenAI\Codex\bin), the User PATH entry, and codex sandbox setup --elevated. The no-winget prerequisite script was checked in Windows PowerShell 5.1: download links resolve and the Node.js LTS lookup returns the current release. It was not run end to end on a Windows Server machine.
  • November 4, 2026: rewrote Step 6c after field review. PATH is now read and written as the raw registry value (keeps %VAR% entries), tools are found on any local drive and from installer registry keys, and stale VS Code sessions are covered (full restart or a PowerShell profile line). Tested in Windows PowerShell 5.1 against a scratch registry key and a temporary profile file.
  • November 5, 2026: reorganized so every command a reader must run sits in its own code block. Conditional steps (the Undefined execution policy fix, the PATH search, the device-code sign-in) now lead with the condition and put the command directly beneath it.
  • November 6, 2026: added the optional embeddable Python section for machines where the standard installer is blocked. The Python 3.13.17 64-bit embeddable ZIP was installed to %LOCALAPPDATA%\Programs\Python\Python313-embed, its SHA-256 was checked against the Python release page, and python.exe --version printed Python 3.13.17. No installer ran, PATH was not changed, and pip was not installed.
  • codex --help and codex login --help confirm --sandbox, --ask-for-approval on-request, --yolo, codex login --device-auth, codex login --with-api-key, codex login status, and codex update.

What's Next?

For teams looking to bring agentic AI into enterprise workflows with HITL controls, private-by-architecture deployment, and outcome-based contracts, talk to the lowtouch.ai team.

About the Author

Rejith Krishnan

Rejith Krishnan

Founder and CEO

Rejith Krishnan is the Founder and CEO of lowtouch.ai, a platform dedicated to empowering enterprises with private, no-code AI agents. With expertise in Site Reliability Engineering (SRE), Kubernetes, and AI systems architecture, he is passionate about simplifying the adoption of AI-driven automation to transform business operations.

Rejith specializes in deploying Large Language Models (LLMs) and building intelligent agents that automate workflows, enhance customer experiences, and optimize IT processes, all while ensuring data privacy and security. His mission is to help businesses unlock the full potential of enterprise AI with seamless, scalable, and secure solutions that fit their unique needs.

LinkedIn →