# Sandbox.Script

A reusable script created by [Sandbox.Game.Scripting](/api/Sandbox.Game/Scripting). Arguments expire after each invocation;
local variables are fresh each run. Use sequentially on the owning context's thread.

- Kind: class
- Namespace: `Sandbox`
- Assembly: `Sandbox.Engine`
- Modifiers: sealed

## Properties

- [`LastError`](/api/Sandbox.Script/LastError): The most recent failure, or null after a successful invocation.

## Methods

- [`Compile`](/api/Sandbox.Script/Compile): Checks that the script compiles with its supplied arguments without executing it. Arguments remain available for the next Run. Failure sets LastError.
- [`HasArgument`](/api/Sandbox.Script/HasArgument): Whether this script references a named external argument. Use before supplying optional host inputs. Names are case sensitive; locals do not count as external arguments.
- [`Run`](/api/Sandbox.Script/Run): Runs the script, returning false and setting LastError on failure.
- [`RunAndReturn`](/api/Sandbox.Script/RunAndReturn): Runs the script and reads its result. Returns default on failure or when no value is returned. An incompatible return type is reported through LastError.
- [`SetArgument`](/api/Sandbox.Script/SetArgument): Supplies a named input for the next invocation only. Unknown names and changes during execution are API usage errors. Supply every input needed to bind host member calls before running.
- [`With`](/api/Sandbox.Script/With): Creates a stack-only invocation with a temporary argument. Chain With to supply more arguments, then call Run or Compile. Names must be referenced by the script; repeated names replace earlier values.
