Embedding Python in Python

Darryl madhobbit at geocities.com
Wed Oct 8 14:35:14 EDT 2003


Hi,

I've been programming in Python for a couple of weeks now and am quite
impressed with the language - it was very easy to learn (it actually
reminds me a lot of programming in BASIC many many years ago - it's
very fast to hack together a couple lines of code in interactive
mode). I'm throwing together a simple little game (sort of a MUD-type
thing) as my first 'big' project, and I thought it would be cool to be
able to script the game in Python.

Basically, I want to be able to type scripts in from within the game
and attach them to objects, monsters, rooms, whatever. Now, I -could-
use exec to run the code, but in an imaginary world where I intended
to actually release this game to the public, I'd need to make sure
that the user won't break anything, either accidentally or
maliciously. So what I'd like to be able to do is essentially sandbox
the code: expose a set of global
variables/functions/modules/classes/whatever to the script for
interaction with the game world, and make sure that the script doesn't
do silly things like file access. A little research has indicated that
previous versions of Python had sandboxing capabilities but these have
broken in new releases and don't look like they're getting fixed any
time soon. So is there any (safe) way to embed Python within itself
for application scripting?

Thanks,
- Darryl Shpak




More information about the Python-list mailing list