Home/Tools/@tpmjs/tools-sprites-exec

spritesExecTool

@tpmjs/tools-sprites-exec

Execute a command inside a sprite and return the output. Supports stdin input for interactive commands. Returns exit code, stdout, stderr, and execution duration. IMPORTANT: If starting a web server, it must listen on port 8080 - this is the Sprites convention for public URLs (use sprites-url-set to make it publicly accessible).

Official
sandbox
v0.1.6
MIT

Interactive Playground

Test @tpmjs/tools-sprites-exec (spritesExecTool) with AI-powered execution

0/2000 characters

Installation & Usage

Install this tool and use it with the AI SDK

1. Install the package

npm install @tpmjs/tools-sprites-exec
pnpm add @tpmjs/tools-sprites-exec
yarn add @tpmjs/tools-sprites-exec
bun add @tpmjs/tools-sprites-exec
deno add npm:@tpmjs/tools-sprites-exec

2. Import the tool

import { spritesExecTool } from '@tpmjs/tools-sprites-exec';

3. Use with AI SDK

import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { spritesExecTool } from '@tpmjs/tools-sprites-exec';

const result = await generateText({
  model: openai('gpt-4o'),
  tools: { spritesExecTool },
  prompt: 'Your prompt here...',
});

console.log(result.text);

Parameters

Available configuration options

Auto-extracted
name
Required
Type: string

Name of the sprite to execute command in

cmd
Required
Type: string

Command to execute (e.g., 'ls -la', 'python script.py')

stdin
Optional
Type: string

Optional stdin input to pass to the command

timeoutMs
Optional
Type: number

Execution timeout in milliseconds (default: 60000)

Schema extracted: 1/16/2026, 3:45:29 AM

README

@tpmjs/sprites-exec

Execute a command inside a sprite and return the output.

Installation

npm install @tpmjs/sprites-exec

Requirements

Usage

import { spritesExecTool } from '@tpmjs/sprites-exec';

// Run a simple command
const result = await spritesExecTool.execute({
  name: 'my-sandbox',
  cmd: 'ls -la /home'
});

console.log(result);
// {
//   exitCode: 0,
//   stdout: 'total 4\ndrwxr-xr-x 2 root root 4096 Jan 15 10:30 .\n...',
//   stderr: '',
//   duration: 45
// }

// Run with stdin input
const pythonResult = await spritesExecTool.execute({
  name: 'my-sandbox',
  cmd: 'python3',
  stdin: 'print("Hello from stdin!")'
});

// For shell features (pipes, redirects, etc), use bash -c
const shellResult = await spritesExecTool.execute({
  name: 'my-sandbox',
  cmd: 'bash -c "echo hello > /tmp/test.txt && cat /tmp/test.txt"'
});

Shell Commands

Commands are executed directly (like exec.Command in Go), not through a shell. This means shell operators like |, >, >>, && won't work directly.

For shell features, wrap your command with bash -c:

// Won't work: cmd: 'echo hello > file.txt'
// Use instead:
cmd: 'bash -c "echo hello > file.txt"'

Input Parameters

ParameterTypeRequiredDescription
namestringYesName of the sprite to execute command in
cmdstringYesCommand to execute (e.g., 'ls -la', 'python script.py')
stdinstringNoOptional stdin input to pass to the command
timeoutMsnumberNoExecution timeout in milliseconds (default: 60000)

Output

FieldTypeDescription
exitCodenumberCommand exit code (0 = success)
stdoutstringStandard output from the command
stderrstringStandard error from the command
durationnumberExecution duration in milliseconds

Error Handling

The tool throws errors in these cases:

  • SPRITES_TOKEN environment variable is not set
  • Sprite not found (HTTP 404)
  • Command execution timeout
  • Invalid or expired API token (HTTP 401)
  • Network errors with descriptive messages

License

MIT

Statistics

Downloads/month

548

GitHub Stars

0

Quality Score

85%

Bundle Size

NPM Keywords

tpmjs
sprites
sandbox
code-execution
ai

Maintainers

thomasdavis(thomasalwyndavis@gmail.com)

Frameworks

vercel-ai