Home/Tools/@tpmjs/unsandbox

runCode

@tpmjs/unsandbox

Execute code with automatic language detection from shebang (e.g., #!/usr/bin/env python3). Simpler than executeCode when your code has a shebang line. Returns stdout, stderr, and detected language.

Official
ai-ml
v0.0.2
MIT
Auto-discovered
🔍

Auto-discovered tool

This tool was automatically discovered from the package exports. The author did not explicitly register it in their package.json. Schema and description were auto-extracted.

Interactive Playground

Test @tpmjs/unsandbox (runCode) 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/unsandbox
pnpm add @tpmjs/unsandbox
yarn add @tpmjs/unsandbox
bun add @tpmjs/unsandbox
deno add npm:@tpmjs/unsandbox

2. Import the tool

import { runCode } from '@tpmjs/unsandbox';

3. Use with AI SDK

import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { runCode } from '@tpmjs/unsandbox';

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

console.log(result.text);

Signature

(code: string) => Promise<unknown>

Tags

ai-ml
ai-sdk
automatic
bin
code
code-execution
detection
env
execute
language
python3
run
sandbox
shebang
tpmjs-tool
unsandbox
usr

Parameters

Available configuration options

Auto-extracted
code
Required
Type: string

The source code to execute. Must include a shebang line (e.g., #!/usr/bin/env python3) for language detection.

Schema extracted: 3/1/2026, 4:28:06 AM

README

@tpmjs/unsandbox

AI SDK tools for secure code execution in 42+ programming languages via unsandbox.com.

Installation

npm install @tpmjs/unsandbox
# or
pnpm add @tpmjs/unsandbox

Setup

Get an API key at unsandbox.com/api-keys and set it as an environment variable:

export UNSANDBOX_API_KEY=your-api-key

Usage

import { streamText } from 'ai';
import { anthropic } from '@ai-sdk/anthropic';
import { executeCode, listLanguages } from '@tpmjs/unsandbox';

const result = streamText({
  model: anthropic('claude-sonnet-4-20250514'),
  tools: {
    executeCode,
    listLanguages,
  },
  system: 'You can execute code in 42+ programming languages using a secure sandbox.',
  prompt: 'Write and run a Python script that calculates the first 10 Fibonacci numbers',
});

Tools

executeCode

Execute code synchronously in a secure sandbox.

import { executeCode } from '@tpmjs/unsandbox';

const result = await executeCode.execute({
  language: 'python',
  code: 'print("Hello, World!")',
});
// { stdout: "Hello, World!\n", stderr: "", exit_code: 0 }

Parameters:

NameTypeRequiredDescription
languagestringYesProgramming language (python, javascript, go, rust, etc.)
codestringYesSource code to execute
input_filesarrayNoFiles to make available in /tmp/input/
network_modestringNo'zerotrust' (default) or 'semitrusted'
ttlnumberNoTimeout in seconds (1-900, default 60)
return_artifactbooleanNoReturn compiled binary for compiled languages
return_wasm_artifactbooleanNoCompile to WebAssembly (C, C++, Rust, Zig, Go)

executeCodeAsync

Execute code asynchronously, returning a job_id for tracking.

import { executeCodeAsync, getJob } from '@tpmjs/unsandbox';

const job = await executeCodeAsync.execute({
  language: 'rust',
  code: 'fn main() { println!("Hello from Rust!"); }',
});

// Check status later
const result = await getJob.execute({ job_id: job.job_id });

runCode

Execute code with automatic language detection from shebang.

import { runCode } from '@tpmjs/unsandbox';

const result = await runCode.execute({
  code: `#!/usr/bin/env python3
print("Auto-detected Python!")`,
});

runCodeAsync

Async version of runCode.

listJobs

List all active jobs for your API key.

import { listJobs } from '@tpmjs/unsandbox';

const jobs = await listJobs.execute({});

getJob

Get status and results of a specific async job.

import { getJob } from '@tpmjs/unsandbox';

const result = await getJob.execute({ job_id: 'abc123' });
// { status: 'completed', stdout: '...', stderr: '...' }

cancelJob

Cancel a running or pending async job.

import { cancelJob } from '@tpmjs/unsandbox';

await cancelJob.execute({ job_id: 'abc123' });

listLanguages

List all 42+ supported programming languages.

import { listLanguages } from '@tpmjs/unsandbox';

const languages = await listLanguages.execute({});

Supported Languages

42+ languages including:

  • Interpreted: Python, JavaScript, TypeScript, Ruby, Perl, PHP, Lua, Bash, R, Elixir, Erlang, Tcl, Scheme, PowerShell, Clojure, Common Lisp, Crystal, Groovy, Deno, AWK, Raku
  • Compiled: C, C++, Go, Rust, Java, Kotlin, COBOL, Fortran, D, Zig, Nim, V, Objective-C, Dart
  • Functional: Julia, Haskell, OCaml, F#, C#, Prolog, Forth

Environment Variables

VariableRequiredDescription
UNSANDBOX_API_KEYYesAPI key from unsandbox.com

Related

License

MIT

Statistics

Downloads/month

15

GitHub Stars

0

Quality Score

72%

Bundle Size

NPM Keywords

tpmjs-tool
ai-sdk
code-execution
sandbox
unsandbox

Maintainers

thomasdavis(thomasalwyndavis@gmail.com)

Frameworks

vercel-ai
runCode | TPMJS | TPMJS