Skip to content

Instantly share code, notes, and snippets.

@megahertz
Created February 16, 2026 10:35
Show Gist options
  • Select an option

  • Save megahertz/c89568947ee08a990ff4d46bca7f422e to your computer and use it in GitHub Desktop.

Select an option

Save megahertz/c89568947ee08a990ff4d46bca7f422e to your computer and use it in GitHub Desktop.
There's a `docker sandbox run codex` command, but it requires Docker Desktop to be installed, which is pretty undesirable on Linux since it replaces Docker Engine with a VM environment. This simple script does similar things.
#!/usr/bin/env bash
set -e
image='docker/sandbox-templates:codex'
case "$1" in
-h|--help)
echo 'Usage: docker-codex [options] [command] [prompt]'
echo 'docker-codex commands:'
echo ' update Pull latest image and update packages'
echo ''
echo ' cat Run the CMD in container'
echo ' cp ...'
echo ' ls ...'
echo ' npm ...'
echo ' pnpm ...'
echo ' sh ...'
echo ''
echo 'Original codex help:'
echo ''
set -- codex --help
;;
update)
docker pull "${image}"
cid=$(docker create "${image}" sh -c 'npm i -g pnpm')
docker start -a "${cid}"
docker commit "${cid}" "${image}"
docker rm "${cid}"
echo 'Codex was updated'
set -- codex --version
;;
cat|cp|ls|npm|pnpm|sh) ;;
*) set -- codex --dangerously-bypass-approvals-and-sandbox "$@" ;;
esac
docker run --init -it --rm \
-v "$(pwd):$(pwd)" -w "$(pwd)" \
-v "${HOME}/.codex:/home/agent/.codex" \
-v "${HOME}/.codex.json:/home/agent/.codex.json" \
-e GIT_AUTHOR_NAME="$(git config user.name)" \
-e GIT_AUTHOR_EMAIL="$(git config user.email)" \
-e TERM=xterm-256color \
-e COLORTERM=truecolor \
"${image}" "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment