[racket] Limiting net-repl provided functions

From: Eli Barzilay (eli at barzilay.org)
Date: Tue Jun 28 02:22:56 EDT 2011

6 minutes ago, Jukka Tuominen wrote:
> I made a simplified test case (below), even left out the net-repl
> part in belief that replacing the eval with sb-eval will do the
> trick in the end. I have the module structure as intended, but still
> can't figure out how to give it as an input to the sandbox
> evaluator. The documentation is there, but a few more examples could
> make it easier to comprehend, especially when not using built-in
> modules.
> [...]
> (require racket/sandbox)
> (require "sb-functions.rkt")
> ;(define sb-eval (make-evaluator 'racket/base))
> (define sb-eval (make-evaluator ... "sb-functions.rkt" ... ));?
> ;; these are ok
> ;(f1) ;bound
> ;(f2) ;bound
> ;(f3) ;bound
> ;(f4) ;unbound
> ;(f5) ;unbound
> ;(f6) ;unbound
> ;; intented sandbox bindings
> ;(sb-eval 'f1) ;bound
> ;(sb-eval 'f2) ;bound
> ;(sb-eval 'f3) ;bound
> ;(sb-eval 'f4) ;unbound
> ;(sb-eval 'f5) ;unbound
> ;(sb-eval 'f6) ;unbound
> ;(sb-eval 'cdr) ;unbound

The sandbox is working in an isolated world (by design, of course), so
you need to do the (require "sb-functions.rkt") inside the sandbox.
For example, just use (sb-eval '(require ...)).

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the users mailing list.