As of 1.0beta6, Pnuts API allows to protect Pnuts packages against untrusted code, using Java2 security API.
The first parameter package is supposed to be a package name that access is controled. An asterisk "*" may appear at the end of the name, following "::" or by itself, to signify a wildcard match.
The second parameter actions is a comma-separated list of the following elements.
For example, a script http://javacenter.sun.co.jp/pnuts/examples/awt/calculator.pnut will try to register a new package named "calculator" and define functions in it. To execute the script under Java2 security, PackagePermission("calculator", "write, add") should be granted in the effective security policy.
The following is an example of a policy file that gives the permission needed by the script.
grant codebase "http://javacenter.sun.co.jp/pnuts/examples/-" { permission pnuts.lang.PackagePermission "*", "write, add"; };${user.home}/.java.policy
The remote script runs in an access control context which is determined from the URL in roughly the same way as applets. The scripts, by default, can not access local file system, system properties, and so on. With a policy file, user can customize the security policy
When a remote script is executed in an anoymous package, the scripts can define variables in the global scope, because no permission is required to access anonymous packages.