From: Russell Wallace
Subject: Sandboxable computation?
Date: 
Message-ID: <jYRZi.23151$j7.434798@news.indigo.ie>
Is there an existing Lisp/Scheme implementation in which running out of 
memory, time or stack space is a catchable exception, rather than 
something that banjaxes the whole process?

Specifically, what I have in mind is a variant of evolutionary 
computation where candidate programs are generated (by various methods) 
and then run. This much is straightforward in Lisp, but a candidate 
program might go into an infinite loop, recurse past available stack 
depth or try to allocate a terabyte of memory; this needs to be 
catchable so the program can be assigned zero fitness and the process 
can continue. Can any existing implementation do this?

(It's for experiment/research purposes so it doesn't have to be of 
commercial quality, a noncommercial-use-only trial version would be 
fine, etc.)

Thanks,

From: jos koot
Subject: Re: Sandboxable computation?
Date: 
Message-ID: <1194873348.568272.125980@57g2000hsv.googlegroups.com>
With MzScheme for example:

(let ((c (make-custodian)) (counter 0))
 (parameterize ((current-custodian c))
  (custodian-limit-memory c 1000 c)
  (let
   ((t
     (thread
      (lambda ()
       (let loop ((i 0)) (set! counter i) (cons i (loop (add1
i))))))))
   (let loop ()
    (sleep 1)
    (if (thread-running? t)  (loop)))
   (printf "thread out of memory with counter: ~s~n" counter)
   (kill-thread t))))
(collect-garbage)

Jos Koot

On Nov 12, 6:58 am, Russell Wallace <···············@gmail.com> wrote:
> Is there an existing Lisp/Scheme implementation in which running out of
> memory, time or stack space is a catchable exception, rather than
> something that banjaxes the whole process?
>
> Specifically, what I have in mind is a variant of evolutionary
> computation where candidate programs are generated (by various methods)
> and then run. This much is straightforward in Lisp, but a candidate
> program might go into an infinite loop, recurse past available stack
> depth or try to allocate a terabyte of memory; this needs to be
> catchable so the program can be assigned zero fitness and the process
> can continue. Can any existing implementation do this?
>
> (It's for experiment/research purposes so it doesn't have to be of
> commercial quality, a noncommercial-use-only trial version would be
> fine, etc.)
>
> Thanks,
From: Russell Wallace
Subject: Re: Sandboxable computation?
Date: 
Message-ID: <o50_i.23164$j7.434546@news.indigo.ie>
jos koot wrote:
> With MzScheme for example:

Right, that looks like the business, checking it out.
Thanks to everyone who replied!
From: Eli Barzilay
Subject: Re: Sandboxable computation?
Date: 
Message-ID: <m3d4uer7xh.fsf@winooski.ccs.neu.edu>
Russell Wallace <···············@gmail.com> writes:

> jos koot wrote:
>> With MzScheme for example:
>
> Right, that looks like the business, checking it out.

If that's what you need, then have a look into the sandbox library
(documented in the mzlib manual).  It does what Jos described, and
much more.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!
From: Alessio
Subject: Re: Sandboxable computation?
Date: 
Message-ID: <1194860950.020502.252430@22g2000hsm.googlegroups.com>
I guess the generated programs will use only a subset of Common Lisp,
won't they? Else, things could go wrong in many other ways than
exausting memory or running forever, e.g. filling the entire hard
disk, deleting random files, damaging the Lisp system by uninterning
symbols or redefining functions, and the list goes on and on and on...
So, if you already stick to a tiny subset of Common Lisp, and you use
only a few functions, you could define a wrapper function for each of
them, to keep track of time and space usage and signal a condition if
limits are exceeded. If this is not feasible, perhaps you could
achieve what you want using multithreading, e.g. having a "scheduler"
thread running periodically which checks if other threads are
exceeding the limits - I don't know much about multithreading in Lisp
so I don't know if this solution is practical or not...
I can't come up with other solutions, I guess the best way would be to
use an implementation which natively provides the functionality you're
asking for, but I don't know if there are any.
Hope this helps...
Alessio Stalla

On Nov 12, 6:58 am, Russell Wallace <···············@gmail.com> wrote:
> Is there an existing Lisp/Scheme implementation in which running out of
> memory, time or stack space is a catchable exception, rather than
> something that banjaxes the whole process?
>
> Specifically, what I have in mind is a variant of evolutionary
> computation where candidate programs are generated (by various methods)
> and then run. This much is straightforward in Lisp, but a candidate
> program might go into an infinite loop, recurse past available stack
> depth or try to allocate a terabyte of memory; this needs to be
> catchable so the program can be assigned zero fitness and the process
> can continue. Can any existing implementation do this?
>
> (It's for experiment/research purposes so it doesn't have to be of
> commercial quality, a noncommercial-use-only trial version would be
> fine, etc.)
>
> Thanks,
From: Darren Bane
Subject: Re: Sandboxable computation?
Date: 
Message-ID: <fh9gss$43p$1@echo.ukshells.co.uk>
In comp.lang.scheme Russell Wallace <···············@gmail.com> wrote:
> Is there an existing Lisp/Scheme implementation in which running out of 
> memory, time or stack space is a catchable exception, rather than 
> something that banjaxes the whole process?
> 
> Specifically, what I have in mind is a variant of evolutionary 
> computation where candidate programs are generated (by various methods) 
> and then run. This much is straightforward in Lisp, but a candidate 
> program might go into an infinite loop, recurse past available stack 
> depth or try to allocate a terabyte of memory; this needs to be 
> catchable so the program can be assigned zero fitness and the process 
> can continue. Can any existing implementation do this?
> 
> (It's for experiment/research purposes so it doesn't have to be of 
> commercial quality, a noncommercial-use-only trial version would be 
> fine, etc.)
> 
> Thanks,

http://mumble.net/~jar/pubs/secureos/
"A Security Kernel Based on the Lambda Calculus".  All the code to
support this should still be in Scheme 48, but may not have been
exercised in a while.

http://www.ccs.neu.edu/scheme/pubs/#icfp99-ffkf
"Programming Languages as Operating Systems (or, Revenge of the Son of
the Lisp Machine)".  This definitely still works, as AFAIK the PLT
development environment and Web server uses it.

Any Scheme running on UNIX with a decent FFI should be able to use
setrlimit, fork, exec and signal handling to do the task too, but
obviously this is less elegant.

I would guess that the PLT library is your best bet.
-- 
Darren Bane
From: ·······@eurogaran.com
Subject: Re: Sandboxable computation?
Date: 
Message-ID: <12ce3bfc-9bc0-459e-986a-efce1d39137e@n20g2000hsh.googlegroups.com>
You would find useful my Common Lisp macro with-max-time, which I
wrote specifically for this. You can find it at
http://www.eurogaran.com/downloads/lisp/limitools/limitime.lsp