() (let ([c (make-custodian)]) (parameterize ([current-custodian c]) (handler in out) (custodian-shutdown-all c))))) (echo-server)) Custodians, combined with the memory accounting feature of the 3m garbage collector, and a number of additional runtime parameters that control additional aspects of the runtime, make it possible to create completely safe sandboxed execution contexts. The racket/sandbox library provides this kind of functionality in a simple way. The following example creates a "REPL server" on the specified port; connecting to this port will look like a plain Racket REPL, except that the evaluation is subject to the various protection aspects of the sandbox. For example, it is not possible to access the filesystem from this REPL, create network connection, run subprocesses, or use too much time or memory. (In fact, this REPL is safe enough to be given out publicly.) #lang racket (require racket/sandbox) (define e (make-evaluator 'racket/base)) (let-values ([(i o) (tcp-accept (tcp-listen 9999))]) (parameterize ([current-input-port i] [current-output-port o] [current-error-port o] [current-eval e] [current-read-interaction (λ (x in) (read in))]) (read-eval-print-loop) (fprintf o "\nBye...\n") (close-output-port o))) Web and network programming The next example implements a web server using the web-server/insta language. Each time a connection is made to the server, the start function is called to get the HTML to send back to the client. #lang web-server/insta ;; A tiny "hello world" web server (define (start request) (response/xexpr '(html (body "Hello World")))) Racket also includes the functions you would need to write scrapers and robots. As an example, the following function would list the Google results for a search string. #lang racket ;; Simple web scraper (require net/url net/uri-codec) (define (let-me-google-that-for-you str) (let* ([g "http://www.google.com/search?q="] [u (string-append g (uri-encode str))] [rx #rx"(?<=<h3 class=\"r\">).*?(?=</h3>)"]) (regexp-match* rx (get-pure-port (string->url u))))) The library also includes support for protocols other than http: #lang racket ;; Sending a timed email alert from racket (require net/sendmail) (sleep (* (- (* 60 4) 15) 60)) ; wait 3h 45m (send-mail-message (getenv "EMAIL") "Parking meter alert!" (list (getenv "EMAIL")) null null '("Time to go out and move your car.")) Graphics Graphic capabilities come in several different flavors that are intended for different audiences. The 2htdp/image library provides convenient functions for constructing images. This library is mainly used by students in HtDP-based courses. In the following example, a sierpinski function is defined and called (at the same time) to generate a Sierpinski triangle of depth 8. #lang racket ;; A picture (require 2htdp/image) (let sierpinski ([n