> ## Documentation Index
> Fetch the complete documentation index at: https://docsuncv2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# debug.setsafeenv

Sets the safe environment table of the specified function.

```luau theme={null}
debug.setsafeenv(func: function, env: table): ()
```

## Parameters

| Parameter | Type       | Description                    |
| --------- | ---------- | ------------------------------ |
| `func`    | `function` | The target function to modify. |
| `env`     | `table`    | The environment table to set.  |

## Returns

`void`

## Example

<CodeGroup>
  ```luau Example 1 theme={null}
  local function test() end
  debug.setsafeenv(test, { myGlobal = 123 })
  -- Function environment is now locked to this table
  ```

  ```luau Example 2 theme={null}
  debug.setsafeenv(test, getgenv())
  ```
</CodeGroup>

<Tip>
  Commonly used to lock down or sandbox a function's environment.
</Tip>
