FUNCTIONS
Execução de WASM
Suba um binário WASM, invoque por HTTP. Roda em sandbox — sem rede, sem filesystem, memória e tempo limitados. Escreva em qualquer linguagem que compile pra WASI, incluindo Go puro.
WASM execution
Upload a WASM binary, invoke it over HTTP. Runs in a sandbox — no network, no filesystem, bounded memory and time. Write it in any language that compiles to WASI, including plain Go.
SYNC resposta na mesma chamada answers in the same call
Endpoints
Endpoints
/api/v1/functions/{name}
envia o binário .wasm (corpo cru)
uploads the .wasm binary (raw body)
/api/v1/functions/{name}/invoke
executa a função
runs the function
/api/v1/functions
lista as funções do cliente
lists the client's functions
/api/v1/functions/{name}
remove uma função
removes a function
A resposta do /invoke é exatamente o que a função gerou (status, headers e corpo) — não é o envelope JSON padrão, é a saída definida pelo próprio código do cliente.
The /invoke response is exactly what the function produced (status, headers and body) — not the standard JSON envelope, it's output the client's own code defines.
Como a função recebe e responde
How the function receives and responds
A função lê um envelope JSON de stdin e escreve um envelope JSON em stdout — sem SDK, qualquer linguagem que compile pra WASI (wasm32-wasip1) funciona, incluindo Go puro (GOOS=wasip1 GOARCH=wasm go build).
The function reads a JSON envelope from stdin and writes a JSON envelope to stdout — no SDK, any language that compiles to WASI (wasm32-wasip1) works, including plain Go (GOOS=wasip1 GOARCH=wasm go build).
// stdin → {"query": {"a":"1"}, "headers": {"content-type":"..."}, "body": "texto"}
// stdout → {"status": 200, "headers": {"content-type":"text/plain"}, "body": "hello"}
Exemplo
Example
cat > main.go <<'EOF'
package main
import (
"encoding/json"
"io"
"os"
)
func main() {
raw, _ := io.ReadAll(os.Stdin)
var req struct{ Body string `json:"body"` }
json.Unmarshal(raw, &req)
json.NewEncoder(os.Stdout).Encode(map[string]any{
"status": 200,
"body": "recebi: " + req.Body,
})
}
EOF
GOOS=wasip1 GOARCH=wasm go build -o minha_funcao.wasm main.go
curl -X PUT "https://api.alicercelabs.com.br/api/v1/functions/minha" \
-H "Authorization: Bearer <token>" \
--data-binary @minha_funcao.wasm
curl -X POST "https://api.alicercelabs.com.br/api/v1/functions/minha/invoke" \
-H "Authorization: Bearer <token>" \
-d "teste"
# → recebi: teste
Segurança do sandbox
Sandbox security
| Controle | Control | Como funciona | How it works |
|---|---|---|---|
| Sem rede | No network | ||
| WASI preview1 não importa sockets — não existe chamada de saída possível, não é uma flag pra desligar. | WASI preview1 doesn't import sockets — there's no outbound call possible, it's not a flag to turn off. | ||
| Sem filesystem | No filesystem | ||
| Nenhum diretório fica visível pro módulo. | No directory is visible to the module. | ||
| Memória e tempo limitados de verdade | Genuinely bounded memory and time | ||
| A execução da VM é efetivamente abortada ao estourar o timeout — não é o servidor desistindo de esperar. | The VM's execution is actually aborted on timeout — not the server giving up on waiting. | ||
Fora de escopo v1: acesso da função a KV/Queue/Edge DB (é sandbox de computação pura); disparo por Cron/Queue (só invoke HTTP síncrono); domínio customizado por função.
Out of scope for v1: function access to KV/Queue/Edge DB (it's a pure compute sandbox); triggering via Cron/Queue (HTTP invoke only); custom domain per function.
Erros possíveis
Possible errors
| Status | Motivo | Reason |
|---|---|---|
| 400 | wasm inválido no deploy, nome inválido, corpo vazio/acima do limite, ou limite de funções atingido | invalid wasm on deploy, invalid name, empty/over-limit body, or function limit reached |
| 401 | token ausente ou inválido | missing or invalid token |
| 404 | função não encontrada | function not found |
| 429 | limite de taxa excedido | rate limit exceeded |
| 500 | saída da função não é um envelope JSON válido, ou ela saiu com código != 0 (stderr incluso, truncado) | the function's output isn't a valid JSON envelope, or it exited with a non-zero code (stderr included, truncated) |
| 503 | Functions não configurado no servidor | Functions not configured on the server |
| 504 | função excedeu o timeout configurado | function exceeded the configured timeout |
Limites
Limits
10.000/dia · 416/hora. Funções por cliente: 20. Tamanho máximo do binário: 10MB. Memória máxima: 32MB. Timeout máximo: 5s (teto absoluto de 30s, mesmo com override). Tudo tunável por cliente via admin.
10,000/day · 416/hour. Functions per client: 20. Max binary size: 10MB. Max memory: 32MB. Max timeout: 5s (absolute ceiling of 30s, even with an override). All tunable per client via admin.