Skip to main content

Luau

API for creating and running isolated Luau environments.

Functions

Luau.createSandbox

Creates a new Luau sandbox.

Luau.createSandbox(): sandbox

Returns

NameTypeDescription
sandboxsandboxThe new sandbox.

Luau.setSandboxGlobals

Sets the global environment for a sandbox.

Luau.setSandboxGlobals(sandbox: sandbox, globals: table)

Parameters

NameTypeDefault ValueDescription
sandboxsandboxRequiredThe sandbox to set the globals for.
globalstableRequiredThe globals to set.

Luau.getScriptPath

Gets the path of the current caller, or alternatively, the path of the caller referenced by the level.

Luau.getScriptPath(level?: number): string?

Parameters

NameTypeDefault ValueDescription
levelnumber?1The level of the caller to get the path of.

Returns

NameTypeDescription
pathstring?The path of the caller.

Luau.getScriptDirectory

Gets the directory of the current caller, or alternatively, the directory of the caller referenced by the level.

Luau.getScriptDirectory(level?: number): string?

Parameters

NameTypeDefault ValueDescription
levelnumber?1The level of the caller to get the directory of.

Returns

NameTypeDescription
directorystring?The directory of the caller.

Luau.run

Runs a script in a sandbox. The given path is used when resolving relative file paths, such as when calling Filesystem.toAbsolutePath.

Luau.run(sandbox: sandbox, scriptPath: string, sourceCode: string): any

Parameters

NameTypeDefault ValueDescription
sandboxsandboxRequiredThe sandbox to run the script in. The executed script has access to the sandbox using the THIS_SANDBOX global.
scriptPathstringRequiredThe path to use for the script. The executed script has access to the path using the SCRIPT_PATH global.
sourceCodestringRequiredThe source code of the script.

Returns

NameTypeDescription
resultanyThe result of the script.

Luau.runFile

Runs a script file in a sandbox.

Luau.runFile(sandbox: sandbox, path: string): any

Parameters

NameTypeDefault ValueDescription
sandboxsandboxRequiredThe sandbox to run the script in.
pathstringRequiredThe path to the script file.

Returns

NameTypeDescription
resultanyThe result of the script.

Luau.createRequire

Creates a function which runs each required module in a sandbox and caches the result.

Luau.createRequire(sandbox: sandbox): fun(path: string): any

Parameters

NameTypeDefault ValueDescription
sandboxsandboxRequiredThe sandbox to run the required modules in.

Returns

NameTypeDescription
requirefun(path: string): anyThe require function.