Yuari
Documentation
Docs/Debug/debug.setsafeenv

debug.setsafeenv

Marks a function, table or thread environment as safe or unsafe.

Syntax

debug.setsafeenv(target?: any, safe?: boolean) -> nil

Parameters

ParameterTypeDescription
target?anyThe function or object being targeted.
safe?booleanThe safe value used by the call.

Returns

TypeDescription
nilThis function does not return a value.

Description

debug.setsafeenv is part of the Debug library. The debug library exposes the internals of the active Luau state, including protos, constants, upvalues and stack frames.

The change is applied directly to the live target, so later reads observe the updated value.

The aliases setuntouched(target?, safe?), setsafeenv(target?, safe?) resolve to the same implementation.

Example

local env = getfenv(0)
debug.setsafeenv(env, false)
print(debug.getsafeenv(env)) -- false

Notes

  • Aliases: setuntouched(target?, safe?), setsafeenv(target?, safe?).
  • Writing protos, constants or upvalues can corrupt a running function; test changes carefully.