I think the main problem is that `make-evaluator` is a function, which
means that it doesn't know what module it's called in. So, relative
paths like 'sub or (submod "." 'sub) don't work.

You could use `quote-module-path` from `syntax/location` like this:

 #lang racket
 (require racket/sandbox
          syntax/location)

 (module* sub racket
   (provide foo)
   (define foo "foo"))

 (make-evaluator 'racket #:requires (list (quote-module-path sub)))

This can work because the `quote-module-path` form expands to an
expression at compile time that identifies the enclosing module at run
time.

At Fri, 29 Jan 2021 21:29:49 -0800 (PST), Vincent Lee wrote:
> 
> Hi all,
> 
> I'm trying to create a sandbox to which I expose a limited set of functions 
> and values from the outside. So far I have this:
> 
> #lang racket
> 
> (require racket/sandbox)
> 
> (module* sub racket
>   (provide foo)
>   (define foo "foo"))
> 
> However if I now run
> 
> (make-evaluator 'racket #:requires 'sub)
> 
> I get an error. I also get an error if I try
> 
> (make-evaluator 'racket #:requires (submod "." 'sub))
> 
> I expect this to work and for `foo` to be available in the sandbox.
> 
> A normal `(require 'sub)` works fine, but according to the docs #:requires 
> takes the exact same form arguments as `require`, so I'm not sure what I'm 
> missing.
> 
> Alternatively, what's the cleanest way to achieve my goal of providing a 
> fixed set of functions and variables into a sandbox?
> 
> Thanks in advance.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email 
> to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/53fc8114-3348-4d7b-b915-cb37dac1b
> d25n%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/20210130080711.54%40sirmail.smtps.cs.utah.edu.

Reply via email to