# Sandbox.ScriptSystem.CreateScript

```csharp
Script CreateScript(string source, ScriptStore locals = null)
```

Creates a reusable script. Syntax and execution errors are reported through [Sandbox.Script.LastError](/api/Sandbox.Script/LastError).
Binding and IL compilation occur on the first run, once arguments are available.
Supply a local store to share persistent fields or preserve them across source edits.
If omitted, the script receives its own local store.

### Parameters

- `source` (`string`)
- `locals` (`ScriptStore`), default `null`

### Returns

`Script`

Declared in [Sandbox.ScriptSystem](/api/Sandbox.ScriptSystem).
Assembly: `Sandbox.Engine`.
