diff --git a/docs/CHANGES.rst b/docs/CHANGES.rst
index 49d2d9d..7bb5c5d 100644
--- a/docs/CHANGES.rst
+++ b/docs/CHANGES.rst
@@ -4,6 +4,9 @@ Changes
 5.1a0 (unreleased)
 ------------------
 
+- Add support for the ``bytes`` and ``sorted`` builtins
+  (`#186 <https://github.com/zopefoundation/RestrictedPython/issues/186>`_)
+
 - Drop install dependency on ``setuptools``.
   (`#189 <https://github.com/zopefoundation/RestrictedPython/issues/189>`_)
 
diff --git a/src/RestrictedPython/Guards.py b/src/RestrictedPython/Guards.py
index 0f2c8fc..e7ed96e 100644
--- a/src/RestrictedPython/Guards.py
+++ b/src/RestrictedPython/Guards.py
@@ -33,6 +33,7 @@ _safe_names = [
     'True',
     'abs',
     'bool',
+    'bytes',
     'callable',
     'chr',
     'complex',
@@ -52,6 +53,7 @@ _safe_names = [
     'repr',
     'round',
     'slice',
+    'sorted',
     'str',
     'tuple',
     'zip'
@@ -174,7 +176,6 @@ for name in _safe_exceptions:
 # one should care.
 
 # buffer
-# bytes
 # bytearray
 # classmethod
 # coerce

Adding "bytes" to allowed builtin names
Having `bytes` would allow a sane way of getting at `OFS.Image.File` data in restricted code under Python 3. `str` is inappropriate because it wants to decode the file content using the default UTF-8 encoding that may not match the actual encoding used by file contents.

Calling this a Zope 4 bugfix because having only `str` for those cases is a recipe for problems.

diff --git a/tests/test_Guards.py b/tests/test_Guards.py
index fe6b2e0..40bd6f0 100644
--- a/tests/test_Guards.py
+++ b/tests/test_Guards.py
@@ -15,6 +15,16 @@ def _write_(x):
     return x
 
 
+def test_Guards_bytes():
+    """It contains bytes"""
+    assert restricted_eval('bytes(1)') == bytes(1)
+
+
+def test_Guards_sorted():
+    """It contains sorted"""
+    assert restricted_eval('sorted([5, 2, 8, 1])') == sorted([5, 2, 8, 1])
+
+
 def test_Guards__safe_builtins__1():
     """It contains `slice()`."""
     assert restricted_eval('slice(1)') == slice(1)

pip install -e .
parse_log_pytest
pytest
pytest pytest-cov pytest-html
3.9
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
coverage==7.8.0
exceptiongroup @ file:///croot/exceptiongroup_1706031385326/work
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
Jinja2==3.1.6
MarkupSafe==3.0.2
packaging @ file:///croot/packaging_1734472117206/work
pluggy @ file:///croot/pluggy_1733169602837/work
pytest @ file:///croot/pytest_1738938843180/work
pytest-cov==6.0.0
pytest-html==4.1.1
pytest-metadata==3.1.1
-e git+https://github.com/zopefoundation/RestrictedPython.git@a31c5572de8a0e6c4f41ea5a977fc27459917c8e#egg=RestrictedPython
tomli @ file:///opt/conda/conda-bld/tomli_1657175507142/work

name: RestrictedPython
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - exceptiongroup=1.2.0=py39h06a4308_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - packaging=24.2=py39h06a4308_0
  - pip=25.0=py39h06a4308_0
  - pluggy=1.5.0=py39h06a4308_0
  - pytest=8.3.4=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tomli=2.0.1=py39h06a4308_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - coverage==7.8.0
      - jinja2==3.1.6
      - markupsafe==3.0.2
      - pytest-cov==6.0.0
      - pytest-html==4.1.1
      - pytest-metadata==3.1.1
prefix: /opt/conda/envs/RestrictedPython

tests/test_Guards.py::test_Guards_bytes tests/test_Guards.py::test_Guards_sorted
tests/test_Guards.py::test_Guards__safe_builtins__1 tests/test_Guards.py::test_Guards__safe_builtins__2 tests/test_Guards.py::test_Guards__guarded_setattr__1 tests/test_Guards.py::test_Guards__write_wrapper__1 tests/test_Guards.py::test_Guards__write_wrapper__2 tests/test_Guards.py::test_Guards__safer_getattr__1 tests/test_Guards.py::test_Guards__safer_getattr__2 tests/test_Guards.py::test_Guards__safer_getattr__3 tests/test_Guards.py::test_call_py3_builtins tests/test_Guards.py::test_safer_getattr__underscore_name
docs/CHANGES.rst src/RestrictedPython/Guards.py
docs/CHANGES.rst src/RestrictedPython/Guards.py