Skip to content

bug: SQLite-based agents fail in sandboxes because the default policy leaves /var/tmp unwritable #5958

Backlog

Description

@mrunalp

User Story

I run coding agents such as Codex in OpenShell sandboxes. Codex 0.172 exits at startup in a sandbox with the default policy, because its SQLite state database can't create a temporary file. I need common agent CLIs to start under the default policy without per-image workarounds.

Problem Statement

The default policy makes /tmp read-write but leaves /var/tmp unwritable. With TMPDIR unset, SQLite on Linux chooses its temporary directory from SQLITE_TMPDIR, TMPDIR, /var/tmp, /usr/tmp and /tmp, in that order. Its check that a directory is writable doesn't account for Landlock, so it picks /var/tmp and then fails to open a file there with SQLITE_CANTOPEN (code 14).

Any workload that uses SQLite temporary files, or that otherwise writes to /var/tmp, fails the same way.

Impact / Why This Matters

Codex 0.172 stops at startup:

Error: failed to initialize sqlite state runtime under /sandbox/.codex: failed to
migrate state DB at /sandbox/.codex/state_5.sqlite: while executing migration 23:
error returned from database: (code: 14) unable to open database file

The cause isn't visible to the user: the error names the database under the writable home directory, not /var/tmp. The workaround is to export TMPDIR and SQLITE_TMPDIR pointing at a writable directory in every image or startup command, or to add /var/tmp to a custom policy.

Acceptance Criteria

  • Under the default policy, a workload that uses SQLite temporary files with TMPDIR unset works, for example Codex 0.172 starting in a sandbox.
  • The default policy page documents the behavior.

Reproduction Steps

  1. Create a sandbox with the default image and policy:

    openshell sandbox create -- sh -c 'touch /tmp/a && echo "/tmp writable"; touch /var/tmp/a || echo "/var/tmp not writable"; sleep infinity'
  2. The output shows /tmp writable and /var/tmp not writable.

  3. Any SQLite program that needs a temporary file, run with TMPDIR unset, fails with unable to open database file.

Environment

Suggested UX (if applicable)

Either option would fix it without user action:

  • Add /var/tmp to the default read-write baseline, next to /tmp.
  • Set TMPDIR=/tmp in the sandbox environment when the image doesn't set it.

Activity

  1. O96a commented on Nov 25, 2026

    @O96a

    Making /var/tmp writable by default is the wrong fix. It's a shared world-writable directory inside the sandbox — that's where agents quietly leave persistence artifacts and where temp-file races become symlink games. You'd trade a startup bug for a class of escape-ish bugs.

    SQLite's unix VFS doesn't want /var/tmp specifically: it probes SQLITE_TMPDIR, then TMPDIR, then /var/tmp, /usr/tmp, /tmp, then cwd, and takes the first one it can write to. So a per-sandbox tmpfs at /tmp with TMPDIR=/tmp in the sandbox env gets Codex to start while the shared dir stays closed.

    Two things that bite people on this path:

    • The VFS resolves and caches the temp directory in a static the first time it needs a temp file. If anything opens a SQLite handle before your entrypoint sets TMPDIR, it pins the bad path for the life of the process. Set it in the sandbox env, not from inside the app.
    • The journal isn't the only file landing there. Temp tables and statement materialization (with temp_store left at default) go to the same place, so a "starts fine" smoke test passes and then it dies mid-task on a large query.

    Before picking the mount point, it's worth pinning down which syscall is actually failing and on which path:

    strace -f -e trace=openat,mkdir,statx -o /tmp/codex.trace codex
    grep -E 'EACCES|EROFS' /tmp/codex.trace
    

    EACCES and EROFS point at different fixes — read-only mount in the way versus mode bits — and I don't want to guess which one this report is hitting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions