The Hacking Sandbox, or hsandbox for short, is a tool to facilitate experimentation with snippets of code written in any of several different programming langauges. When hsandbox is executed, your favorite text editor will be run with a template for the given language. You just have to input the logic you intend to experiment with and write down the sandbox file, and the file will be automatically run and its output exposed next to the code itself, in a different screen region.
Simply run the command with:
$ hsandbox <language extension>[<version>] [options]
$ hsandbox c
This will create a C sandbox with a template ready to be run, and every time you write the file it will get compiled and executed in the other screen region.
With some languages, it's also possible to pass a version number to the sandbox, so that the specific version of the language is used. For instance:
$ hsandbox py3.2
The following options are currently supported:
- Continue editing the last written sandbox for the given language.
- Split the screen vertically rather than horizontally.
The last sandbox file for a given language may be found at ~/.sandbox.<ext>.
Given its nature, it's trivial to add support for new programming languages in hsandbox. Here are the currently supported ones:
- C (hsandbox c)
- C++ (hsandbox cc)
- Clojure (hsandbox clj)
- C# (mono) (hsandbox cs)
- Erlang (hsandbox erl)
- Go (hsandbox go)
- Haskell (ghc) (hsandbox hs)
- Java (hsandbox java)
- Lua (hsandbox lua)
- Objective C (hsandbox m)
- Pascal (gpc) (hsandbox pas)
- PHP (hsandbox php)
- Perl (hsandbox pl)
- Python (hsandbox py)
- Ruby (hsandbox rb)
- Shell (sh) (hsandbox sh)
If you'd like to change one of the provided language templates and customize it for your needs, just write a text file with the name ~/.sandbox.<ext>.template. Every time a new sandbox is run for the given language, this template will be used.
The template may use the special string "<cursor>" (no quotes) to mark the place where the editor should start editing the template. This will be stripped out before the editor is run, and the proper line where the string was found will be made available to the editor command in the $HSANDBOX_LINE environment variable (see below).
The following environment variables may be defined to customize the behavior of hsandbox:
- If defined, the given command will be executed to run the editor. This enables different parameters to be used for hsandbox. The specified command may use the variable $HSANDBOX_LINE to make the editor start in the right input line for the given language template.
- Will be passed to the gcc compiler when compiling C sandboxes.
- Will be passed to the g++ compiler when compiling C++ sandboxes.
The following dependencies are required to run hsandbox:
- python-pyinotify (to avoid busy waits, works without it)
The source code is available via Bazaar and Git:
$ bzr branch lp:hsandbox $ # or $ git clone http://github.com/niemeyer/hsandbox.git
Tarballs are also available.
You can report issues in both Launchpad and GitHub:
Gustavo Niemeyer <firstname.lastname@example.org>