Simulators
The Python your code runs on
To run your code the simulator needs a Python that has the modal package: the one its Docker image carries, or the one on its PATH. Its compute view reads "isolated": false until a first command has run in a root of its own:
curl -s "$RYSTIC_URL/_rystic/inspect?view=compute" | jq -c '{isolated, live}'
# -> {"isolated":false,"live":0}
The simulator’s Docker image carries Python 3.12.16 with modal 1.6.3 and the 28 packages it depends on, at /opt/rystic/python, first on PATH. The simulator runs your code on it, so a docker run needs no Python on your machine.
Outside the image the simulator runs your code on python3 from its PATH, on Linux only, and that interpreter needs modal installed. The simulator is built against modal==1.6.3.
To run your code on another interpreter:
- Set
RYSTIC_COMPUTE_PYTHONto its path, such as one in a volume you mount. - Mount an environment of your own over
/opt/rystic/python. - Build on the image and add packages to its interpreter as root with
python3 -m pip install, which is how a function’s own imports are met.
A call whose interpreter is missing, or has no modal, fails with an error that names what is missing.
From a plain docker run your code runs as ordinary processes inside the container, with the container’s own network and files. An absolute path your code names, such as /tmp/out.txt, is then the container’s own: everything the simulator runs shares it, and a reset keeps it. The simulator’s file operations and snapshots never hold it. They hold only what your code writes under its working directory, HOME and TMPDIR.
Your code then runs as the simulator’s own user. It cannot read the simulator’s own process: a license or an API key you pass in the environment, and the simulator’s memory, stay out of its reach. It can read and change every file that user can, which includes other sandboxes’ files, the simulator’s data and lease folders, and a license or a key you pass as a file. It can reach any address the container can, and it can stop the simulator. So pass credentials in the environment, and run code you do not trust the way the next paragraph describes.
Starting the container with --security-opt seccomp=unconfined --security-opt systempaths=unconfined lets the simulator give each process a network that reaches only the simulator and a filesystem of its own: what your code writes there, the simulator’s file operations read and its snapshots hold. The exceptions are the system directories the sandbox borrows from the container, such as /usr and /etc, which are read-only and in no snapshot, and /proc and /dev, which only your code reads. Docker Desktop allows that. A Linux host may still refuse it, and your code then runs as before. GET /_rystic/inspect?view=compute answers "isolated": true once your first command has run that way.
The simulator runs up to 16 commands at once and keeps up to 64 sandboxes running. The command a sandbox itself runs counts as the sandbox, not as one of the 16. A call that would start one more fails with an error that names the limit and the setting that raises it: RYSTIC_COMPUTE_MAX_LIVE for commands, RYSTIC_COMPUTE_MAX_SANDBOXES for sandboxes.
A function’s containers count among the 16. Calls sent together run on as many containers as the function’s own limit and the 16 allow, and a call past that waits for a container instead of failing. A container with no call to run gives its place to a command that needs one.
The simulator keeps the first 8388608 bytes (8 MiB) of each output stream of a command, and RYSTIC_COMPUTE_OUTPUT_BYTES raises that. Reading a larger file through the simulator’s file operations fails with an error that names the setting. It is never answered short.
Ask the image which Python it carries
docker run --rm registry.rystic.ai/modal-twin:<ver> python3 -c 'import modal, sys; print(modal.__name__, sys.prefix)'
# prints: modal /opt/rystic/python
Use another SDK version
The image’s Python holds one modal version. To use another, install it into a copy of the image’s Python and name the copy with RYSTIC_COMPUTE_PYTHON:
docker volume create modal-env
docker run --rm --user root -v modal-env:/env registry.rystic.ai/modal-twin:<ver> \
sh -c 'cp -a /opt/rystic/python/. /env/ && /env/bin/python3 -m pip install -q "modal==<your version>"'
docker run --rm -v modal-env:/env:ro registry.rystic.ai/modal-twin:<ver> \
/env/bin/python3 -c 'import modal, sys; print(modal.__name__, sys.prefix)'
# prints: modal /env
docker run -d -p 8080:8080 -v modal-env:/env:ro -e RYSTIC_COMPUTE_PYTHON=/env/bin/python3 \
registry.rystic.ai/modal-twin:<ver>
Add packages to the image’s Python
Build on the image and install into its Python as root:
FROM registry.rystic.ai/modal-twin:<ver>
USER root
RUN python3 -m pip install numpy
USER rystic
docker build -t my-modal-simulator .
docker run --rm my-modal-simulator python3 -c 'import numpy, sys; print(numpy.__name__, sys.prefix)'
# prints: numpy /opt/rystic/python