API reference

Based on the runtime bundled with Cobalt. These entries describe the inspected implementation, not a guarantee that every function has passed a live test. Compatibility entries call out partial implementations and placeholders.

58 entries

Environment

getgenv

getgenv(): table

Returns the shared Cobalt execution environment.

Example
getgenv().message = "Hello"
print(getgenv().message)

getrenv

getrenv(): table

Returns the runtime’s constructed environment table. This is not unrestricted access to every game script’s environment.

getexecutorversion

getexecutorversion(): string

Returns the bundled runtime version rather than the desktop application version.

identifyexecutor

identifyexecutor(): (string, string)

Returns the executor name and runtime version as two values.

Aliases: whatexecutor

Example
local name, version = identifyexecutor()
print(name, version)

loadstring

loadstring(source: string, chunkName: string?): (function?, string?)

Compiles Luau source without executing it. Returns a function on success, or nil and an error on failure. Compilation uses the desktop runtime and can time out.

Example
local fn, err = loadstring("return 2 + 2", "example")
if fn then print(fn()) else warn(err) end

queue_on_teleport

queue_on_teleport(source: string)

Submits source to the runtime’s teleport queue. Execution in the next client depends on attachment and runtime availability.

Aliases: queueonteleport

Filesystem

readfile

readfile(path: string): string

Reads a runtime workspace file. If a write is queued for that path, returns the queued content. Raises a file error when the runtime cannot read it.

writefile

writefile(path: string, content: string)

Queues a file write. Replaces a pending write for the same path. Disk synchronization happens later, so keep the desktop app running until pending writes finish.

Example
writefile("example.txt", "Hello, Cobalt")
print(readfile("example.txt"))

appendfile

appendfile(path: string, content: string)

Appends to a pending write, or reads the existing file and queues its updated contents. A missing file can raise an error; create it with writefile first.

loadfile

loadfile(path: string): (function?, string?)

Reads and compiles a runtime workspace file. Returns the compiled function without calling it. Empty content returns a no-op function.

Aliases: dofile

Compatibility: dofile is an alias of loadfile here; it does not execute the file automatically.

Example
local fn, err = loadfile("example.luau")
if fn then fn() else warn(err) end

isfile

isfile(path: string): boolean

Checks whether a file exists, taking pending writes and deletions into account.

isfolder

isfolder(path: string): boolean

Checks whether a folder exists, taking pending folder creation and deletion into account.

makefolder

makefolder(path: string)

Queues folder creation. Cancels a pending deletion for the same folder.

delfile

delfile(path: string)

Queues deletion of a runtime workspace file. This scripting API is separate from the editor explorer’s Recycle Bin behavior.

delfolder

delfolder(path: string)

Queues deletion of a runtime workspace folder.

listfiles

listfiles(path: string): {string}

Returns tracked paths beneath the supplied prefix, including pending changes. It can include descendants beyond the immediate directory; ordering is not guaranteed.

getcustomasset

getcustomasset(path: string): string

Asks the runtime for an asset URI for a workspace file. Flushes a pending write to that file first; failures raise an error.

Network

request

request(options: table): table

Sends an HTTP request. Required: Url (string). Optional: Method (GET by default), Body (string), Headers (table). Supported methods: GET, POST, PUT, DELETE, PATCH. Header names are normalized to lowercase; default User-Agent is Cobalt. The options table is modified in place. The runtime also adds client/device and game-session metadata headers. Returns Success and StatusCode, with StatusMessage, Body, Headers and Version when available. Success means an HTTP 2xx response.

Aliases: http.request, http_request

Use the capitalized Body field. Error responses can omit Body and Headers.

Example
local response = request({
    Url = "https://example.com",
    Method = "GET"
})
print(response.StatusCode, response.Body)

HttpGet

HttpGet(url: string, returnRaw: boolean?): any

Returns the HTTP response body by default. Passing false JSON-decodes the body. This helper explicitly sends a Roblox-style User-Agent rather than the default request User-Agent.

HttpPost

HttpPost(url: string, body: any, contentType: string?): table

Returns the request response table. The current wrapper passes a lowercase body field, while request reads Body, so the supplied body is not forwarded correctly.

Limited: use request({Url = url, Method = "POST", Body = text, Headers = {["Content-Type"] = "application/json"}}) instead.

WebSocket.connect

WebSocket.connect(url: string): table

Connects through the desktop runtime to a ws:// or wss:// URL. Returns a connection with Send, Close, OnMessage and OnClose. Events expose Connect, Once and Wait. Close the connection when finished; connection errors can raise.

Example
local socket = WebSocket.connect("wss://your-server.example/socket")
socket.OnMessage:Connect(function(message)
    print(message)
end)
socket:Send("hello")
-- socket:Close()

Encoding

base64.encode

base64.encode(content: string): string

Base64-encodes a string through the runtime.

Aliases: base64_encode, crypt.base64.encode, crypt.base64encode, crypt.base64_encode

Example
print(base64.encode("Cobalt"))

base64.decode

base64.decode(content: string): string

Decodes a Base64 string through the runtime.

Aliases: base64_decode, crypt.base64.decode, crypt.base64decode, crypt.base64_decode

crypt.hash

crypt.hash(data: string, algorithm: string): string

Requests a digest from the runtime. Algorithm names ignore case, hyphens and underscores. Recognized names: md5, sha1, sha224, sha256, sha384, sha512, sha512_224, sha512_256, sha3_224, sha3_256, sha3_384, sha3_512.

Example
print(crypt.hash("Cobalt", "sha-256"))

crypt.generatebytes

crypt.generatebytes(size: number): string

Requests the specified number of generated bytes from the runtime. The Luau wrapper does not establish their encoding or randomness guarantees.

crypt.encrypt

crypt.encrypt(data: string, key: string, iv: string?, mode: string): (string, string)

Delegates encryption to the runtime and returns the result plus the decoded IV from the response. Mode is required; recognized modes are ECB, CBC, OFB, CFB, CTR, GCM, CCM, XTS and OCB. An omitted IV is passed as an empty string.

Native key sizes, output encoding and mode-specific behavior are not established by the client wrapper; this reference does not promise interoperability.

crypt.decrypt

crypt.decrypt(data: string, key: string, iv: string?, mode: string): string

Delegates decryption to the runtime using the same mode names as crypt.encrypt. Mode is required; an omitted IV is passed as an empty string.

lz4compress

lz4compress(data: string): string

Returns runtime-compressed LZ4 data; raises on runtime failure.

lz4decompress

lz4decompress(data: string, size: number): string

Decompresses LZ4 data using the supplied uncompressed size; raises on runtime failure.

Example
local text = "Hello, Cobalt"
local packed = lz4compress(text)
print(lz4decompress(packed, #text))

Instances & drawing

cloneref

cloneref(instance: Instance): Instance

Returns a new runtime proxy referring to the same underlying instance. It does not clone the instance.

compareinstances

compareinstances(a: Instance, b: Instance): boolean

Compares the underlying instances behind runtime proxies.

gethui

gethui(): Instance

Returns a cloned proxy to the runtime-created HUI folder under CoreGui. This does not establish that an interface is undetectable.

Drawing.new

Drawing.new(kind: string): DrawingObject

Creates a GUI-backed drawing object. Implemented kinds: Line, Text, Circle, Square, Image, Quad and Triangle. Shared fields include Visible, ZIndex, Transparency and Color; objects expose Remove and Destroy. Transparency 1 is opaque and 0 is transparent.

Example
local label = Drawing.new("Text")
label.Text = "Cobalt"
label.Position = Vector2.new(40, 40)
label.Size = 18
label.Color = Color3.new(1, 1, 1)
label.Visible = true
-- label:Remove()

isrenderobj

isrenderobj(object: any): boolean

Checks whether the object exposes the runtime’s Drawing Object marker.

getrenderproperty

getrenderproperty(object: DrawingObject, property: string): any

Reads a property after checking isrenderobj.

setrenderproperty

setrenderproperty(object: DrawingObject, property: string, value: any)

Writes a property after checking isrenderobj.

cleardrawcache

cleardrawcache()

Clears all children of the runtime’s drawing GUI.

Utilities

setclipboard

setclipboard(content: any)

Converts a non-nil value to a string and sends it to the desktop clipboard. Empty strings are ignored.

Aliases: toclipboard, setrbxclipboard

isrbxactive

isrbxactive(): boolean

Returns the runtime’s Roblox focus flag, updated by WindowFocused and WindowFocusReleased events.

Aliases: isgameactive, iswindowactive

setfpscap

setfpscap(cap: number)

Writes UserSettings().GameSettings.FramerateCap. Values at or below zero are converted to math.huge; actual acceptance depends on the client.

getfpscap

getfpscap(): number

Reads UserSettings().GameSettings.FramerateCap.

Compatibility

getsenv

getsenv(script: Instance): table

Returns only {script = script}. It does not retrieve the script’s actual environment.

Compatibility stub

setreadonly

setreadonly(value: table): table

Returns table.clone(value). It does not change the original table’s read-only state; a second boolean argument is not used.

Compatibility behavior

isreadonly

isreadonly(value: table): boolean

Returns table.isfrozen(value).

hookfunction

hookfunction(original: function, replacement: function): function?

Scans the caller environment, then the executor environment, replacing the first matching direct value. Returns the replacement when found, otherwise nil. It does not globally patch a function or return its original closure.

Aliases: replaceclosure

Limited environment replacement

getthreadcontext

getthreadcontext(): number

Returns a local compatibility variable, initially 3. This is not a verified read of native thread identity.

Aliases: getthreadidentity, getidentity

setthreadidentity

setthreadidentity(value: number)

Only changes the local variable returned by getthreadcontext. It does not perform a native privilege change.

Aliases: setidentity, setthreadcontext

debug.getinfo

debug.getinfo(functionOrLevel: function | number, options: string?): table

Builds a table from debug.info. Defaults to flnSu. Supports S, f, l, n, u and a; nups is reported as -1 rather than an actual upvalue count.

debug.getconstant

debug.getconstant(fn: function, index: number): any

Indexes a fixed placeholder array containing "print" and "Hello, world!". It does not inspect fn.

Placeholder

debug.getconstants

debug.getconstants(fn: function): table

Returns fixed example constants rather than the supplied function’s constants.

Placeholder

debug.getstack

debug.getstack(level: number, index: number?): any

Returns "ab" when index is supplied, otherwise {"ab"}. It does not inspect stack values.

Placeholder

debug.getprotos

debug.getprotos(...): table

Returns a synthetic callable table whose indexed functions return true. It does not enumerate function prototypes.

Aliases: debug.getproto

Placeholder

debug.getupvalue

debug.getupvalue(...)

Returns nil without inspecting an upvalue.

Not implemented

debug.setconstant

debug.setconstant(...)

Returns nil without changing constants.

Not implemented

debug.setstack

debug.setstack(...)

Returns nil without changing stack values.

Not implemented

debug.setupvalue

debug.setupvalue(...)

Returns nil without changing upvalues.

Not implemented

Keybind map

ActionShortcut
New tabCtrl + N
Import fileCtrl + O
Save active fileCtrl + S
Save As / ExportCtrl + Shift + S
Execute active scriptCtrl + Enter
Toggle explorerCtrl + B
Toggle output panelCtrl + `
Move focused tabCtrl + Shift + ← / →