Skip to main content

Quick Start

SpadeBox provides a set of sandboxed tools for AI agents: file system access, HTTP fetching, and a JavaScript REPL. This page shows how to get up and running in TypeScript, Python, and Rust.

Installation

npm install @spadebox/spadebox

Creating a SpadeBox Instance

Start by creating a SpadeBox and enabling the desired tools. All tools are disabled by default and require explicit opt-in.

const sb = new SpadeBox()
sb.enableFiles(sandboxPath)
.enableJs()
.enableHttp()
.allow('*', ['GET', 'HEAD'])

Listing Available Tools

SpadeBox exposes tool metadata in the format expected by LLM tool-calling APIs (name, description, and a JSON Schema for parameters). For instance, to create an OpenAI API-compatible tool list:

const tools = sb.tools().map((t) => ({
type: 'function' as const,
function: {
name: t.name,
description: t.description,
parameters: JSON.parse(t.inputSchema),
},
}))

Dispatching Tool Calls

When the API returns a tool call, the tool name and JSON-encoded parameters can be passed directly to call_tool. The result tells you whether the call succeeded and contains the tool's output.

const result = await sb.callTool('read_file', JSON.stringify({ path: 'hello.txt' }))
assert(!result.isError)
assertEquals(result.output, 'hi from callTool')

Agent Loop

Here is a minimal agent loop that connects SpadeBox to an LLM and drives a multi-turn conversation with tool use:

async function runTurn(messages: Message[]): Promise<void> {
while (true) {
const response = await chat(messages)
messages.push({ role: 'assistant', content: response.content, tool_calls: response.tool_calls })

if (!response.tool_calls?.length) {
if (response.content) console.log(`\n${CYAN}Agent:${RESET} ${response.content}\n`)
return
}

for (const call of response.tool_calls) {
const { name, arguments: args } = call.function
console.log(`\n${BLUE}[call]${RESET} ${GRAY}${name}(${args})${RESET}`)

const result = await sb.callTool(name, args)
const tag = result.isError ? `${RED}[error]${RESET}` : `${GREEN}[ok]${RESET}`
console.log(`${tag} ${GRAY}${result.output}${RESET}`)

messages.push({ role: 'tool', tool_call_id: call.id, content: result.output })
}
}
}

Full example