Description Usage Arguments Details Value Examples
We assume all files surrounding the to be evaluated files have different user ids
and file modes not allowing the supplied user id to read them. One way to do that
is to just set all files within the evaluation directories to root:root
removing group and others the rights to read (or write or execute). We therefore
also chmod
the supplied file back to mode “0644” ensuring that
the file can be read so that the expression can be evaluated—but nothing else
should be in reach.
1 2 3 4 5 | source_and_eval_safe(file, expr, uid = NULL)
eval_safe_as(expr, uid = NULL)
source_and_eval_safe_with_hiding(file, expr, uid = NULL, path = NULL)
|
file |
A filename with an R file to be source, typically containing the student code to be evaluated safely. |
expr |
An expression to be evaluate by |
uid |
Optional numeric or character user id identifying the user id with
(presumably lower) privileges as which the code is running; the numeric uid
is obtained via |
path |
Optional path to a file that should be hidden before evaluation happens. It is then unhidden on exit. |
The source_and_eval_safe_with_hiding
variant can hide a given file, for
example containing a reference answer, but assigning it to a unique temporary name so
that it cannot be sourced.
The eval_safe_as
convenience function fetches the (numeric) user id
before calling unix::eval_safe
; it is equivalent to source_and_eval_safe
but does not involve a file.
Note that you must run these functions as the ‘root’ user in order to set the uid.
A value of the expr
sourced from file
and evaluated by
uid
, or NULL in case of error.
1 2 3 4 5 | ## Not run:
n <- sample(3:20, 1) # random payload
res <- source_and_eval_safe("code/fib.R", fib(n), "ag")
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.