Conversation
|
For testing, the best is to do: R starts then with: |
|
Thank you very much for your willingness to contribute! I will do a deeper review of this soon, but one conceptual adjustment that I would like to start with is I would like to make the sandbox opt in. Essentially the sandbox is only needed when working in "polluted" environments where base/recommended packages are cohabitating with userland packages and we need to isolate that. With your miniconda example tahts what you hit. On the flip side, the renv sandbox causes some issues around performance, opt-in behavior, where to put the sandbox, filesystem boundaries, etc. So what I'd like to do is we work to get this implemented, but it should instead behave where either
the config setting should take precedence over the environment variable. One thing we also need to test against, is we should be addressing that sandbox in the rv R process as well by making sure it also understands what to do - this is something that isn't in scope with renv since renv runs in the R process. So we need rv to help "activate" the environment properly, it also needs to itself provide isolation during package installs to make sure those R processes also understand what and where to point to. This turns into us now modifying forceably the R_LIBS_X variables to not be a single path, the current rv library, but also the sandbox if its enabled so it'd be like "path/to/rv/lib:path/to/sandbox". I also want to explicitly call out your putting in detailed steps you've been using for testing - very much appreciated :-) Would you mind seeing how much of this makes sense/you can implement and we can start helping as well to work from the base you've put together. |
|
@dpastoor Thank you for the answer!
I see this is true, when R was installed globally using sudo. Thus, as soon as the user uses any R in a conda environment, he eventually would wish a sandboxing.
This should be doable. The config-first setting I totally agree.
The |
|
Now I implemented RV_SANDBOX_ENABLE and the Important is that after every change The testing is not so easy - many manual steps: Forgetting
Actually, instead of |
Problem
Base R always appends
.Libraryto.libPaths(). On some systems (notably macOS, but also Linux, and likely also Windows) the system library can contain user-installed packages, which then leak intorvprojects and break isolation/determinism/reproducibility of the rv project. I discussed this in the closed issue #400 in detail. I now created #403 to re-explain it clearer.Prior art: renv system-library sandbox
rv’s approach here follows the same isolation principle used by renv (tidyverse): sandbox the system library so that only packages with
Priority: baseorPriority: recommendedare visible via.Library, preventing leakage of user-installed packages from the system library to the rv project.References:
renv::sandbox— The default library sandbox: https://rstudio.github.io/renv/reference/sandbox.htmlrenv::config—sandbox.enabled(describes linking/copying base+recommended into a sandbox and instructing R to use it as system library): https://rstudio.github.io/renv/reference/config.htmlrenv::load()(mentions setting up the system library sandbox during activation): https://rstudio.github.io/renv/reference/load.htmlWhat this PR does
This PR adds renv-style system library sandboxing to the generated
rv/scripts/activate.R:rv/sandbox/<rver>/<arch>DESCRIPTIONhasPriority: baseorPriority: recommended.Libraryto the sandbox before calling.libPaths()README.mdandCHANGELOG.mdare added but require your adjustment.activate.Rtemplate insrc/consts.rsis the ground truth.Startup safety
Implementation avoids
installed.packages()during startup (which depends onutils) and instead scansDESCRIPTIONfiles using base-only functions, so R can still load default packages normally.Opt-out
Set
RV_SANDBOX=0to disable sandboxing for a session.How to verify
rv initin a fresh directoryR.libPaths() .LibraryExpected: .Library points inside rv/sandbox/... and .libPaths() ends with that sandbox.
Opt-out check:
Expected: .Library is the normal system library again.