Skip to Content
DocumentationCode Execution

Code Execution

Stacknet supports sandboxed code execution — models can write and run code in isolated containers operated by aISP nodes. This enables data analysis, computation, file generation, and tool building directly within conversations.

How it works

┌───────────────────────────────────────────────┐ │ User Request │ │ "Calculate the prime factors of 1234567890" │ └──────────────────────┬────────────────────────┘ ┌───────────────────────────────────────────────┐ │ Model writes code │ │ │ │ def prime_factors(n): │ │ factors = [] │ │ d = 2 │ │ while d * d <= n: │ │ while n % d == 0: │ │ factors.append(d) │ │ n //= d │ │ d += 1 │ │ if n > 1: │ │ factors.append(n) │ │ return factors │ │ │ │ print(prime_factors(1234567890)) │ └──────────────────────┬────────────────────────┘ ┌───────────────────────────────────────────────┐ │ aISP Sandbox Execution │ │ │ │ ┌─────────────────────────────────────────┐ │ │ │ Container (gvisor/kata) │ │ │ │ --network none │ │ │ │ --cap-drop ALL │ │ │ │ 4GB memory · 4 CPU · 600s timeout │ │ │ │ │ │ │ │ stdout: [2, 3, 3, 5, 3607, 3803] │ │ │ │ exit: 0 │ │ │ └─────────────────────────────────────────┘ │ │ │ │ aISP earns tokens for execution │ │ Deterministic attestation recorded │ └──────────────────────┬────────────────────────┘ ┌───────────────────────────────────────────────┐ │ Model interprets results │ │ │ │ "The prime factors of 1,234,567,890 are: │ │ 2 × 3² × 5 × 3607 × 3803" │ └───────────────────────────────────────────────┘

Sandbox security

Every code execution runs in a hardened container:

ControlSetting
Runtimegvisor or kata containers
Network--network none (no internet)
Capabilities--cap-drop ALL (minimal privileges)
Memory4GB limit
CPU4 cores
Timeout600 seconds
FilesystemEphemeral (destroyed after execution)

Deterministic attestation

Each execution produces a verifiable attestation:

attestation = SHA-256( imageDigest + inputHash + outputHash + exitCode + environmentHash )

Warm pools

aISP nodes maintain warm pools of pre-started containers for sub-second execution startup:

Cold start: ~2-5 seconds (container creation) Warm start: <100ms (pre-warmed container)

Operators who maintain warm pools receive:

  • Paperwork bonus on execution tasks
  • Priority routing for sandbox-capable tasks
  • Reputation boost for consistent availability

Usage

Automatic

Models with code execution capability will automatically write and run code when appropriate:

const response = await client.chat.completions.create({ model: 'preview', messages: [ { role: 'user', content: 'Generate a chart of Bitcoin prices for the last 30 days' } ], tools: [{ type: 'code_execution' }], })
Last updated on