Skip to content

Quickstart

In about ten minutes you will run Sefra on your machine, watch it allow and refuse orders from an AI agent, approve a large order as a person, and read the audit trail.

The sandbox contains Sefra, a sample ERP and a test sign-in. It listens on 127.0.0.1 only. It is for learning, so do not put real data in it.

You need:

  • Docker with Compose v2
  • curl and jq
  • Free local ports 18180 to 18183
  • The sandbox image address and registry credential from your pilot welcome note

Sign in to the registry with the command in your welcome note, then set the image address:

export SEFRA_SANDBOX_IMAGE=<image address from your welcome note>
mkdir -p sefra-sandbox && cd sefra-sandbox
docker run --rm "$SEFRA_SANDBOX_IMAGE" | tar -x
./sandbox up

The first start downloads the images and takes a few minutes. It finishes with Sefra is ready. Run every later command from this sefra-sandbox directory.

Get an access token for the agent:

AGENT=$(./sandbox token agent)

Tokens last one hour. If a request later answers 401, run that line again.

Ask for the IT department’s budget:

curl -sS -X POST http://127.0.0.1:18180/v1/executions \
  -H "Authorization: Bearer $AGENT" \
  -H "Content-Type: application/json" \
  -d '{"intent": "procurement.get_budget", "input": {"department": "it-ops"}}' \
  | jq '{status, output: .steps[0].output}'
{
  "status": "succeeded",
  "output": { "currency": "EUR", "remaining_minor": 5000000 }
}

Amounts are in minor units, so 5000000 is EUR 50,000.00.

Order two laptops for EUR 2,400.00. A write carries an Idempotency-Key, so a retry can never create a second order:

curl -sS -X POST http://127.0.0.1:18180/v1/executions \
  -H "Authorization: Bearer $AGENT" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: quickstart-laptops-1" \
  -d '{"intent": "procurement.create_purchase_order",
       "input": {"vendor_id": "v_1001", "sku": "LAPTOP-14", "quantity": 2,
                 "unit_price_minor": 120000, "currency": "EUR", "department": "it-ops"},
       "rationale": "Laptops for two new hires"}' \
  | jq '{status, output: .steps[0].output}'

The status is succeeded, and the output holds the new order’s po_id. Sefra made the ERP call with its own credential. The agent’s token would not be accepted by the ERP.

Now try to order far more than the budget allows:

curl -sS -X POST http://127.0.0.1:18180/v1/executions \
  -H "Authorization: Bearer $AGENT" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: quickstart-too-many-1" \
  -d '{"intent": "procurement.create_purchase_order",
       "input": {"vendor_id": "v_1001", "sku": "LAPTOP-14", "quantity": 1000,
                 "unit_price_minor": 120000, "currency": "EUR", "department": "it-ops"}}' \
  | jq '.envelope.error | {code, rule: .violations[0].rule, hint: .violations[0].hint}'
{
  "code": "POLICY_DENIED",
  "rule": "procurement.budget_exceeded",
  "hint": "Reduce the quantity or request a budget increase."
}

Nothing reached the ERP. The hint is written for the agent, so it can correct itself instead of retrying blindly.

Orders of EUR 20,000.00 or more need a finance approver. Order 25 desks:

RESPONSE=$(curl -sS -X POST http://127.0.0.1:18180/v1/executions \
  -H "Authorization: Bearer $AGENT" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: quickstart-desks-1" \
  -d '{"intent": "procurement.create_purchase_order",
       "input": {"vendor_id": "v_1001", "sku": "DESK-STANDING", "quantity": 25,
                 "unit_price_minor": 100000, "currency": "EUR", "department": "it-ops"},
       "rationale": "Standing desks for the new office"}')
echo "$RESPONSE" | jq '{status, required: .approval.required}'
EXECUTION=$(echo "$RESPONSE" | jq -r .execution_id)
APPROVAL=$(echo "$RESPONSE" | jq -r .approval.approval_id)

The status is pending_approval, and nothing has reached the ERP. Approve it as Maria, the finance approver:

SEFRA_OPERATOR_TOKEN=$(./sandbox token approver) ./sandbox sefra approvals approve "$APPROVAL" --comment "Budgeted this quarter"
./sandbox wait "$EXECUTION" | jq '{status, output: .steps[0].output}'

The status is now succeeded. Sefra checked the policy again with fresh facts before placing the order.

To decide in a browser instead, open http://127.0.0.1:18181/approvals and sign in with the username approver, leaving the claims field empty.

Every step was recorded, and each event is chained to the one before it by a hash:

SEFRA_OPERATOR_TOKEN=$(./sandbox token admin) ./sandbox sefra executions audit "$EXECUTION" \
  | jq -r '.events[] | "\(.seq)  \(.type)  \(.actor)"'

You will see the request arrive, policy run, the approval requested and decided, policy run again, and the ERP call complete. Check the whole chain:

./sandbox sefra audit verify

To explore the same record visually, open the console at http://127.0.0.1:18181/console/ and sign in with the username admin.

  • The agent could only request actions that an intent defines.
  • Policy allowed one order, refused one and held one, using live budget data.
  • A person approved the held order, and the decision is on the record.
  • The agent never held the ERP credential.

Write rules of your own in Your first bundle. The sandbox stays useful throughout the docs. Stop it with ./sandbox down, which keeps Sefra’s records and restarts the sample ERP with fresh data. Delete everything with ./sandbox destroy.