Skip to content

Python: chmod is accepted but not enforced, and seeded files can't be made read-only #2387

Closed

Description

@sh3raawii

I'm using bashkit as the tool surface for an LLM agent. The VFS holds a read-only projection of a document corpus — the model searches and reads it, then cites what it found. Nothing running inside the sandbox should be able to rewrite those files.

I can't find a way to enforce that from Python. chmod is accepted but doesn't stop a write:

import asyncio
from bashkit import Bash

async def main():
    bash = Bash(files={"/data/report.txt": "revenue 40,200,000\n"})
    bash.chmod("/data/report.txt", 0o444)

    r = await bash.execute("echo 'revenue 999' > /data/report.txt; echo rc=$?; cat /data/report.txt")
    print(r.stdout, end="")
    print("stderr:", repr(r.stderr))

asyncio.run(main())
rc=0
revenue 999
stderr: ''

I expected the redirect to fail with EACCES.

There doesn't seem to be another route either:

Enforcing the mode bits, or a per-mount read-only flag on mount(), would both solve it.

bashkit 0.1.2, Python 3.13.

Activity

  1. chaliy commented on Sep 8, 2026

    @chaliy
    Contributor

    Thanks for reporting this. There is a gap: Python cannot currently mark an arbitrary in-memory filesystem mount read-only while leaving the rest of the sandbox writable. We'll add per-mount read-only support and cover both Python and Node.

    For an entirely read-only sandbox, current Python supports this (verified on 0.17.1):

    from bashkit import Bash
    
    bash = Bash(
        files={"/data/report.txt": "revenue 40,200,000\n"},
        readonly_filesystem=True,
    )

    Reads work; filesystem mutations are denied, including writes to /tmp. This is an option for the search/read/cite workflow if writable scratch space is unnecessary.

    We are not planning full POSIX chmod permission enforcement for this change. VFS mode bits remain metadata; read-only mounts provide host-enforced protection that sandbox code cannot undo with chmod.

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