s&box Console Commands: ConCmd & ConVar Explained

If you come from Garry’s Mod or Source 1, s&box’s console works differently — there’s no big server.cfg or fixed ConVar list. Instead, commands and variables are defined in C# with attributes, and you pass them on the launch line. Here’s how ConCmd and ConVar actually work in s&box.

The big difference from Source 1

s&box has a deliberately small configuration surface. There’s no server.cfg and no master ConVar list like the old engine. Anything you’d put in a config, you instead pass as a launch parameter when the server boots — those run as ConVars or ConCmds at startup.

ConCmd — console commands

A [ConCmd] attribute turns a C# method into a console command. The backend converts your string arguments to the method’s parameter types automatically:

[ConCmd( "greet" )]
public static void Greet( string name )
{
    Log.Info( $"Hello {name}" );
}

Add the ConVarFlags.Server flag to force a command to run on the server, and make the first parameter a Connection to know who ran it — essential for admin commands.

ConVar — console variables

A [ConVar] exposes a value you can read and change from the console. ConVars take flags that can be combined:

  • Saved — persists between sessions.
  • Replicated — synced from server to all clients.
  • UserInfo — sent from client to host in UserInfo.
  • GameSetting — exposed on the game’s creation screen.

Permissions — who can run what

Command and variable access is gated at the engine level with permission flags — Admin, Server, Replicated, and Cheat — plus Connection.HasPermission and the NetPermission enum. This is how you stop a random client from running server-only or cheat commands. Who counts as an admin is set in users/config.json — see our user permissions guide.

Generate them without the boilerplate

Writing ConCmd/ConVar attributes with the right flags by hand is error-prone. Our free ConCmd / ConVar generator builds the C# snippet with your chosen flags and parameters, and the admin commands guide covers running them on a live server. Hosting on XGamingServer s&box hosting gives you console and file access to test it all.

FAQ

Is there a server.cfg in s&box? No — pass settings as launch parameters; they execute as ConVars/ConCmds on boot.

How do I make a command server-only? Add ConVarFlags.Server to the [ConCmd] attribute.

How do I know who ran a command? Make the method’s first parameter a Connection.

Sources: s&box Docs — Console Variables.