[racket] Problems using Sandbox and Scribble

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Jan 27 16:03:58 EST 2015

The `#:requires` option of `make-evaluator` requires the named modules
in the sandbox's namespace, but the module instances are distinct from
any instances in the original namespace.

To attach the original namespace's instances to the sandbox's
namespace, use the `sandbox-namespace-specs` parameter:

 (define safe-eval
   (parameterize ([sandbox-namespace-specs
                   (append (sandbox-namespace-specs)
                           '(scribble/manual scribble/racket))])
     (make-evaluator 'racket/base 
                     #:requires '(scribble/manual scribble/racket))))

At Tue, 27 Jan 2015 13:22:01 -0700, Lucas Paul wrote:
> Hi.
> 
> I want to evaluate some scribble things (in a sandbox) and then
> combine them with other scribble things I already have lying around.
> But I'm running into a problem.
> 
> If I, for example, make a nicely formatted (racket) code block in a
> sandbox, and then put it in a (para) outside of that sandbox, the
> world explodes. Here is a minimal example:
> 
> #lang racket
> 
> (require racket/sandbox
>          scribble/manual)
> 
> (define safe-eval
>   (make-evaluator 'racket/base #:requires '(scribble/manual scribble/racket)))
> 
> (pretty-print (racket foo))  ; Gives one output
> (pretty-print (safe-eval '(racket foo)))  ; Gives a slightly DIFFERENT output
> 
> (para (racket foo))  ; Finishes happily
> (para (safe-eval '(racket foo)))  ; Error
> 
> ; end
> 
> This is the error I get:
> 
> para: contract violation
>   expected: pre-content?
>   given: (cached-element (style "RktSym" (list 'tt-chars (css-addition
> '(collects #"scribble" #"racket.css")) (tex-addition '(collects
> #"scribble" #"racket.tex")))) "foo" (vector (style "RktSym" (list
> 'tt-chars (css-addition '(collects #"scribble" #"racket...
>   in: an element of
>       the rest argument of
>       (->*
>        ()
>        (#:style (or/c style? string? symbol? #f))
>        #:rest
>        (listof pre-content?)
>        paragraph?)
>   contract from:
>       <pkgs>/scribble-lib/scribble/base.rkt
>   blaming: anonymous-module
>    (assuming the contract is correct)
>   at: <pkgs>/scribble-lib/scribble/base.rkt:337.2
> 
> What is going on? Why does the same piece of code have two different
> results depending on where it's executing? And most importantly, is
> there a way for me to get this to work the way I /want/?
> 
> - Lucas Paul
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Posted on the users mailing list.