Skip to content

CLI Reference

sema [OPTIONS] [FILE] [-- SCRIPT_ARGS...]

Flags & Options

FlagDescription
-e, --eval <EXPR>Evaluate expression, print result if non-nil
-p, --print <EXPR>Evaluate expression, always print result
-l, --load <FILE>Load file(s) before executing (repeatable)
-q, --quietSuppress REPL banner
-i, --interactiveEnter REPL after running file or eval
--no-initSkip LLM auto-configuration
--no-llmDisable LLM features (same as --no-init)
--chat-model <NAME>Set default chat model
--chat-provider <NAME>Set chat provider
--embedding-model <NAME>Set embedding model
--embedding-provider <NAME>Set embedding provider
--vmUse bytecode VM instead of tree-walker
--sandbox <MODE>Restrict dangerous operations (see below)
-V, --versionPrint version
-h, --helpPrint help

Subcommands

sema ast

Parse source into an AST tree.

sema ast [OPTIONS] [FILE]
FlagDescription
-e, --eval <EXPR>Parse expression instead of file
--jsonOutput AST as JSON

sema compile

Compile a source file to a .semac bytecode file. The compiled file can be executed directly with sema (auto-detected via magic number). See Bytecode File Format for details on the format.

sema compile [OPTIONS] <FILE>
FlagDescription
-o, --output <FILE>Output file path (default: input with .semac extension)
--checkValidate a .semac file without executing
bash
# Compile to bytecode
sema compile script.sema                   # → script.semac
sema compile -o output.semac script.sema   # explicit output path

# Run the compiled bytecode (auto-detected)
sema script.semac

# Validate a bytecode file
sema compile --check script.semac
# ✓ script.semac: valid (format v1, sema 1.6.2, 3 functions, 847 bytes)

sema build

Build a standalone executable from a Sema source file. The resulting binary embeds the compiled bytecode, all transitive imports, and any explicitly included assets into a self-contained executable. See Executable Format for details on the binary format.

sema build [OPTIONS] <FILE>
FlagDescription
-o, --output <PATH>Output executable path (default: filename without extension)
--include <PATH>...Additional files or directories to bundle (repeatable)
--runtime <PATH>Sema binary to use as runtime base (default: current exe)
bash
# Build a standalone executable
sema build script.sema                        # → ./script
sema build script.sema -o myapp              # explicit output path

# Bundle additional files
sema build script.sema --include data.json   # bundle a file
sema build script.sema --include assets/     # bundle a directory

# Run the standalone executable
./myapp --arg1 --arg2

sema disasm

Disassemble a compiled .semac bytecode file, printing a human-readable listing of the main chunk and all function templates.

sema disasm [OPTIONS] <FILE>
FlagDescription
--jsonOutput as JSON
bash
sema disasm script.semac          # human-readable text
sema disasm --json script.semac   # structured JSON output

sema completions

Generate shell completion scripts. See Shell Completions for installation instructions.

sema completions <SHELL>

Supported shells: bash, zsh, fish, elvish, powershell.

Examples

bash
# Parse a file into an AST tree
sema ast script.sema

# Parse an expression into JSON AST
sema ast -e '(+ 1 2)' --json

# Load a prelude before starting the REPL
sema -l prelude.sema

# Load helpers, then run a script
sema -l helpers.sema script.sema

# Run a script and drop into REPL to inspect state
sema -i script.sema

# Quick one-liner for shell pipelines
sema -p '(string/join (map str (range 10)) ",")'

# Run without LLM features (faster startup)
sema --no-llm script.sema

# Use the bytecode VM (faster execution for compute-heavy code)
sema --vm script.sema

# Compile to bytecode and run
sema compile script.sema
sema script.semac

# Use a specific model
sema --chat-model claude-haiku-4-5-20251001 -e '(llm/complete "Hello!")'

# Run with shell commands disabled
sema --sandbox=no-shell script.sema

# Deny multiple capabilities
sema --sandbox=no-shell,no-network,no-fs-write script.sema

# Strict mode (no shell, fs-write, network, env-write, process, llm)
sema --sandbox=strict script.sema

# Maximum restriction (deny all dangerous operations)
sema --sandbox=all script.sema

# Restrict file operations to specific directories
sema --allowed-paths=./data,./output script.sema

# Combine sandbox and path restrictions
sema --sandbox=strict --allowed-paths=./data script.sema

Shebang Scripts

Sema supports #! (shebang) lines, so you can write executable scripts:

sema
#!/usr/bin/env sema
(println "Hello from a sema script!")

Make the file executable and run it directly:

bash
chmod +x script.sema
./script.sema

The shebang line is only allowed on the first line of a file and is treated as a comment. #!/usr/bin/env sema uses the standard env lookup, so it works regardless of how sema was installed (Homebrew, Cargo, manual, etc.).

Sandbox

The --sandbox flag restricts access to dangerous operations. Functions remain callable but return a PermissionDenied error when invoked.

Modes

ModeDescription
strictDeny shell, fs-write, network, env-write, process, llm (reads allowed)
allDeny all capabilities
Comma-separatede.g. no-shell,no-network — deny specific capabilities

Capabilities

CapabilityFunctions affected
shellshell
fs-readfile/read, file/exists?, file/list, file/info, load, ...
fs-writefile/write, file/append, file/delete, file/mkdir, file/copy, ...
networkhttp/get, http/post, http/put, http/delete, http/request
env-readenv, sys/env-all
env-writesys/set-env
processexit, sys/pid, sys/args, sys/which
llmllm/complete, llm/chat, llm/send

Functions not listed (arithmetic, strings, lists, maps, println, path/join, etc.) are never restricted.

Path Restrictions

The --allowed-paths flag restricts all file operations to specific directories. Paths are canonicalized, so traversal attacks like ../../etc/passwd are blocked.

bash
# Only allow reading/writing within ./project and /tmp
sema --allowed-paths=./project,/tmp script.sema

When --allowed-paths is set, any file operation (file/read, file/write, file/list, etc.) targeting a path outside the allowed directories returns a PermissionDenied error. This works independently of --sandbox — you can use both together:

bash
# Allow filesystem but only within ./data
sema --sandbox=no-shell,no-network --allowed-paths=./data script.sema

Environment Variables

VariableDescription
ANTHROPIC_API_KEYAnthropic API key (auto-detected)
OPENAI_API_KEYOpenAI API key (auto-detected)
GROQ_API_KEYGroq API key (auto-detected)
XAI_API_KEYxAI/Grok API key (auto-detected)
MISTRAL_API_KEYMistral API key (auto-detected)
MOONSHOT_API_KEYMoonshot API key (auto-detected)
GOOGLE_API_KEYGoogle Gemini API key (auto-detected)
OLLAMA_HOSTOllama server URL (default: http://localhost:11434)
JINA_API_KEYJina embeddings API key (auto-detected)
VOYAGE_API_KEYVoyage embeddings API key (auto-detected)
COHERE_API_KEYCohere embeddings API key (auto-detected)
SEMA_CHAT_MODELDefault chat model name
SEMA_CHAT_PROVIDERPreferred chat provider
SEMA_EMBEDDING_MODELDefault embedding model name
SEMA_EMBEDDING_PROVIDERPreferred embedding provider

Deprecated aliases

SEMA_DEFAULT_MODEL and SEMA_LLM_PROVIDER still work but are deprecated. Use SEMA_CHAT_MODEL and SEMA_CHAT_PROVIDER instead.

REPL Commands

CommandDescription
,quit / ,qExit the REPL
,help / ,hShow help
,envShow user-defined bindings
,builtinsList all built-in functions

REPL Features

Tab Completion

The REPL supports tab completion for:

  • All 350+ built-in function names (e.g., string/trstring/trim)
  • Special forms (defdefine, defun, defmacro, ...)
  • User-defined bindings
  • REPL commands (,,quit, ,help, ,env, ,builtins)

Multiline Input

The REPL automatically detects incomplete expressions (unbalanced parentheses) and continues on the next line:

sema> (define (factorial n)
  ...   (if (= n 0)
  ...     1
  ...     (* n (factorial (- n 1)))))
sema> (factorial 10)
3628800

History

Command history is saved to ~/.sema/history.txt and persists across sessions.