AI agents
You can let an AI coding agent (Claude, Cursor, Copilot, or anything that can make HTTP requests) build your game's server logic for you. The agent uses your project's AI key to read, test, write and roll back Functions and global properties.
Set it up in one minute
- Open your project and go to API keys.
- Press Generate AI key. Only the project owner can do this.
- Copy the prompt shown under Paste this into your AI agent and give it to your agent. It already contains the key and the instructions the agent needs.
That is all. Ask the agent for what you want, for example "add a shop where players can buy a sword for 50 coins".
What the AI key can and cannot do
| Can | Cannot |
|---|---|
| Read every Function and global property | Read player or room data |
| Create, update, turn off and delete Functions | Change API keys, the team, settings or billing |
| Test Functions in the sandbox without saving | Delete the project |
| Set and delete global properties | Connect to your game as a player |
| See the version history and restore a version |
Every change the agent makes is saved in History with the label AI agent, so you can always see what it did and undo it. Revoke or rotate the key at any time from API keys.
The agent API
Base URL: https://getnetstack.com/api/agent. Every request needs this header:
Authorization: Bearer ns_ai_...
| Method | Path | Body | What it does |
|---|---|---|---|
| GET | /api/agent |
Project overview: Functions with code and language, built-ins, global properties, recent versions, limits, a guide to each language and this endpoint list | |
| PUT | /api/agent/functions |
{ name, code, language?, description?, enabled?, message? } |
Create or update a Function. language is javascript, typescript, gdscript, python or lua |
| DELETE | /api/agent/functions |
{ name, message? } |
Delete a Function |
| POST | /api/agent/functions/test |
{ code, language?, args?, playerId?, player?, room?, global?, players? } |
Run code in the sandbox against sample state. Nothing is saved |
| PUT | /api/agent/globals |
{ key, value } |
Set a global property to any JSON value |
| DELETE | /api/agent/globals |
{ key } |
Delete a global property |
| GET | /api/agent/versions |
The last 50 versions | |
| GET | /api/agent/versions/:number |
The Functions exactly as they were in that version | |
| POST | /api/agent/versions/:number |
Restore that version |
message is a short note that shows up in History, for example "Add a cooldown to useItem". If you leave it out, NetStack writes one for you.
Saving a Function with the same name as a built-in (such as sendChat) replaces the built-in for this project. Live games pick up every change within about 5 seconds.
The AI key allows 120 requests per minute and 30 test runs per minute. Errors come back as { "error": "..." } with a normal HTTP status code, and the message says what to fix.
Choosing a language
Functions can be written in JavaScript, TypeScript, GDScript, Python or Lua. Every language gets the same ctx API, the same sandbox, the same limits and the same test runner, and one project can mix them. Each Function has a language field:
language |
Entry point | Reject a call with | Guide |
|---|---|---|---|
javascript (default) |
export default async function (ctx, args) { ... } |
throw new NetStackError(code, message) |
Writing Functions |
typescript |
export default async function (ctx: any, args: Args) { ... } |
throw new NetStackError(code, message) |
TypeScript |
gdscript |
func run(ctx, args): |
fail(code, message) |
GDScript |
python |
def run(ctx, args): |
raise NetStackError(code, message) |
Python |
lua |
function run(ctx, args) ... end |
error(NetStackError(code, message)) or fail(code, message) |
Lua |
Tell your agent which one you want, or let it match your game: GDScript for Godot, TypeScript or JavaScript for web games, Lua if your engine already scripts in Lua. The prompt from the dashboard tells the agent to match the language your existing Functions use. GET /api/agent lists each Function's language, and its languageGuide gives the agent the entry point, how to reject a call, a docs link and starter code for every language.
When saving or testing, the agent sends language in the request body. Leaving it out when saving keeps the Function's current language (new Functions are JavaScript). Leaving it out on a test run means JavaScript, so the agent should always send the same language to both. Code is syntax-checked in its language before it is saved.
Limits (every language)
| Limit | Value |
|---|---|
| CPU time per call | 150 ms |
| Memory per call | 32 MB |
| Source per Function | 20,000 characters |
| Functions per project | 50 |
| Property writes per call | 100 |
| Broadcasts per call | 50 |
No network, filesystem, timers or imports (Python may import math, random, json, time and string). If a call fails or throws, none of its writes or broadcasts happen.
Examples
Save a Function with curl. This one gives the player a coin each time it is called:
curl https://getnetstack.com/api/agent/functions \
-X PUT \
-H "Authorization: Bearer $NETSTACK_AI_KEY" \
-H "content-type: application/json" \
-d '{
"name": "addCoins",
"language": "javascript",
"message": "Let players earn coins",
"code": "export default async function (ctx, args) {\n const coins = (ctx.player.get(\"coins\") ?? 0) + 1;\n ctx.player.set(\"coins\", coins);\n return { coins };\n}"
}'
The response is { "ok": true, "version": 4 }. If the code has a syntax error, the response is a 400 with the error message, and nothing is saved.
Here is the same addCoins Function in each language. Send it as code with the matching language. A test run with "player": { "coins": 4 } returns { "coins": 5 } in every language.
JavaScript, "language": "javascript":
export default async function (ctx, args) {
const coins = (ctx.player.get("coins") ?? 0) + 1;
ctx.player.set("coins", coins);
return { coins };
}
TypeScript, "language": "typescript":
export default async function (ctx: any, args: { amount?: number }) {
const coins: number = (ctx.player.get("coins") ?? 0) + 1;
ctx.player.set("coins", coins);
return { coins };
}
GDScript, "language": "gdscript":
func run(ctx, args):
var coins = ctx.player.get("coins", 0) + 1
ctx.player.set("coins", coins)
return { "coins": coins }
Python, "language": "python":
def run(ctx, args):
coins = ctx.player.get("coins", 0) + 1
ctx.player.set("coins", coins)
return {"coins": coins}
Lua, "language": "lua":
function run(ctx, args)
local coins = (ctx.player:get("coins") or 0) + 1
ctx.player:set("coins", coins)
return { coins = coins }
end
Test before saving. This dry run checks the Python version and saves nothing:
curl https://getnetstack.com/api/agent/functions/test \
-X POST \
-H "Authorization: Bearer $NETSTACK_AI_KEY" \
-H "content-type: application/json" \
-d '{
"language": "python",
"player": { "coins": 4 },
"code": "def run(ctx, args):\n coins = ctx.player.get(\"coins\", 0) + 1\n ctx.player.set(\"coins\", coins)\n return {\"coins\": coins}\n"
}'
For a longer example in all five languages, including rejecting a call and broadcasting to the room, see section 5 of llms.txt.