Skip to content

agent_sdk: write sandbox files as utf-8, not the locale default - #110

Draft
amburger66 wants to merge 1 commit into
masterfrom
fix-sandbox-setup-utf8-encoding
Draft

agent_sdk: write sandbox files as utf-8, not the locale default#110
amburger66 wants to merge 1 commit into
masterfrom
fix-sandbox-setup-utf8-encoding

Conversation

@amburger66

Copy link
Copy Markdown

What

setup_sandbox_directory wrote CLAUDE.md, .claude/validate_sandbox.py, .claude/settings.json and notes.md with a bare Path.write_text(), which encodes using the locale's preferred encoding. All four now pass encoding="utf-8" explicitly.

Why

VALIDATE_SANDBOX_SCRIPT contains an em dash at index 3026, so on a C/POSIX locale the write raised:

'ascii' codec can't encode character '—' in position 3026: ordinal not in range(128)

Sandbox setup runs once per agent query, so this was not one unlucky query — every query and every final-submission nudge failed the same way, and the run ended with:

Bilevel solve failed: no captured plan after 0 completed agent queries.
Tasks solved: 0 / 1

The cause is invisible from the logs: agent_model_based_approach catches the exception per query and logs only the message, so the failure reads like an agent/planning problem rather than a file write. It was found while bringing up pybullet_domino_real on real hardware, where it blocked the run entirely.

The system-prompt write further down the same function already passed encoding="utf-8"; this makes the rest consistent with it.

Verification

Ran setup_sandbox_directory directly under LC_ALL=C LANG=C PYTHONCOERCECLOCALE=0 PYTHONUTF8=0 (preferred encoding ANSI_X3.4-1968):

  • pristine origin/master — raises the error above
  • this branch — completes and writes every file (CLAUDE.md, .claude/validate_sandbox.py, notes.md, subdirectories)

yapf --diff clean against .style.yapf; file compiles.

Note for reviewers

PYTHONUTF8=1 is an equivalent workaround for anyone hitting this before the fix lands, but the explicit encoding is the right fix — these files are always UTF-8 regardless of the operator's locale.

setup_sandbox_directory wrote CLAUDE.md, validate_sandbox.py, settings.json
and notes.md with bare Path.write_text(), which encodes using the locale's
preferred encoding. VALIDATE_SANDBOX_SCRIPT contains an em dash at index
3026, so under a C/POSIX locale the write died with

    'ascii' codec can't encode character '—' in position 3026

Sandbox setup runs once per agent query, so this was not a single bad
query: every query and every final-submission nudge failed identically,
and the task ended with "no captured plan after 0 completed agent
queries" after exhausting all solve attempts. The traceback never named
the sandbox, because the approach catches the failure per query and logs
only the message.

The system-prompt write a few lines further down already passed
encoding="utf-8"; this makes the rest of the function consistent with it.

Verified by running setup_sandbox_directory under LC_ALL=C with C-locale
coercion disabled: origin/master raises the error above, this commit
completes and writes every file.
@amburger66 amburger66 self-assigned this Jul 31, 2026
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