Security & Sandboxing
By default, Autolang scripts can't reach the network or the file system at all. You explicitly grant access โ and only to the paths or domains you specify.
If you haven't registered any libraries yet, start with Native Libraries first.
๐ HTTP Domain Rules
Scripts using std/http can only reach domains you've whitelisted. Use setAllowedDomainsRules() with a list of rules โ plain prefix strings or full regex patterns.
import { ACompiler, AllowRuleType } from 'autolang-compiler';
const compiler = await ACompiler.create();
compiler.setAllowedDomainsRules([
// Plain prefix โ matches "api.example.com", "api.example.com/v2", etc.
"api.example.com",
// Explicit prefix form (same as the string above)
[AllowRuleType.PLAIN_PREFIX, "cdn.example.com"],
// Regex โ allows any *.example.org subdomain
[AllowRuleType.REGEX, ".*\\.example\\.org"],
// Object form (also supported)
{ type: AllowRuleType.REGEX, value: "httpbin\\.org" },
]);
// Http.get("https://api.example.com/data") โ succeeds
// Http.get("https://evil.com/steal") โ throws SecurityErrorNo rules = no requests
setAllowedDomainsRules(), all HTTP requests are blocked regardless of what the script tries. This is the default.๐ File System Permissions
File operations are disabled by default. You turn them on per-operation (read, write, delete) and optionally restrict which paths are accessible. You can also set a base directory โ all relative paths inside scripts will resolve from there.
import { ACompiler, AllowRuleType } from 'autolang-compiler';
const compiler = await ACompiler.create();
// Enable/disable individual operations
compiler.setAllowFileRead(true); // allow File read
compiler.setAllowFileWrite(true); // allow File write
compiler.setAllowFileDelete(false); // block File.delete()
// Restrict which paths are accessible
compiler.setAllowedFilePathsRules([
"data/", // plain prefix
[AllowRuleType.REGEX, "tmp/.*\\.log"], // only .log files in tmp/
{ type: AllowRuleType.PLAIN_PREFIX, value: "config/" },
]);
// Resolve relative paths from this base
compiler.setFileBasePath("/app/sandbox/");
// File("data/notes.txt", FileMode.READ) โ /app/sandbox/data/notes.txt โ
// File("../../etc/passwd", FileMode.READ) โ blockedFor a complete listing of all compiler methods, see the Type Reference.
๐ ๏ธ Main Source Config
Libraries get their own LibraryConfig when you register them. For the main user script, use setMainSourceConfig() to set the same options โ typically to relax or tighten what the script is allowed to write.
import { ACompiler, LibraryConfig } from 'autolang-compiler';
const compiler = await ACompiler.create();
const config: LibraryConfig = {
allowNonNullAssertion: true, // allow the ! postfix operator
allowLateinitKeyword: true, // allow lateinit var declarations
};
compiler.setMainSourceConfig(config);
await compiler.compileAndRun("main.atl", `
lateinit var name: String
name = "Autolang"
println(name!)
`);
console.log(compiler.getOutput()); // AutolangSee Examples for real-world usage combining libraries, security rules, and AI interaction.
