Skip to content

Sprites

Sprites provides a direct interface for defining containers at runtime and securely running arbitrary code inside them.

This can be useful if, for example, you want to:

  • Execute code generated by a language model
  • Create isolated environments for running untrusted code
  • Check out a git repository and run a command against it, like a test suite or linter
  • Run containers with arbitrary dependencies and setup scripts

Each individual environment is called a Sprite and can be created using the CLI or SDKs:

Terminal window
# Create a sprite
sprite create my-sprite
# Execute commands
sprite exec python -c "print('hello')"
# Stream output from long-running commands
sprite exec "for i in {1..10}; do date +%T; sleep 0.5; done"
# Destroy when done
sprite destroy my-sprite

Sprites automatically hibernate when inactive, with no compute charges while idle. When you execute a command or make a request to a Sprite’s URL, it automatically wakes up with all your data intact.

Sprites currently hibernate after 30 seconds of inactivity. This timeout is not configurable yet.

A Sprite is considered active if any of the following are true:

  1. It has an active command running (via exec)
  2. Its stdin is being written to
  3. It has an open TCP connection over its URL
  4. A detachable session is running

Sprites currently use a fixed resource configuration (8 vCPUs, 8192 MB RAM, 100 GB storage). These values are not configurable yet.

Set the working directory for command execution:

Terminal window
sprite exec -dir /home/sprite/project npm test

Set environment variables for command execution:

Terminal window
sprite exec -env MY_SECRET=hello bash -c 'echo $MY_SECRET'

The default Sprite environment includes:

  • Languages: Node.js, Python, Go, Ruby, Rust, Elixir/Erlang, Java, Bun, Deno
  • AI Tools: Claude CLI, Gemini CLI, OpenAI Codex, Cursor
  • Utilities: Git, curl, wget, vim, and common development tools

Run setup commands after creating a Sprite:

const sprite = await client.createSprite('my-sprite');
// Install custom dependencies
await sprite.exec('pip install pandas numpy matplotlib');
await sprite.exec('npm install -g typescript');
// Clone a repository
await sprite.exec('git clone https://github.com/your/repo.git /home/sprite/project');

For interactive applications, enable TTY mode:

Terminal window
# Open interactive shell (TTY enabled by default)
sprite console
# Or with exec
sprite exec -tty bash

Create sessions that persist even after disconnecting:

Terminal window
# Create a detachable session
sprite exec -detachable "npm run dev"
# List active sessions
sprite exec
# Attach to a session
sprite exec -id <session-id>
Terminal window
sprite exec

If you have the name of a Sprite, you can get a handle to it:

Terminal window
# Set active sprite for current directory
sprite use my-sprite
# Commands now use this sprite
sprite exec echo "hello"
Terminal window
# List all sprites
sprite list
# List with prefix filter
sprite list --prefix "dev-"

Every Sprite has a unique URL for HTTP access:

Terminal window
# Get sprite URL
sprite url
# Make URL public (no auth required)
sprite url update --auth public
# Make URL require sprite auth (default)
sprite url update --auth default

Updating URL settings is available via the CLI, Go SDK, or REST API (the JS SDK does not expose a helper yet).

Forward local ports to your Sprite:

Terminal window
# Forward local port 3000 to sprite port 3000
sprite proxy 3000
# Forward multiple ports
sprite proxy 3000 8080 5432

Get notified when ports open in your Sprite:

const cmd = sprite.spawn('npm', ['run', 'dev']);
cmd.on('message', (msg) => {
if (msg.type === 'port_opened') {
console.log(`Port ${msg.port} opened on ${msg.address} by PID ${msg.pid}`);
// Auto-forward or notify user
}
});

Save and restore Sprite state:

Terminal window
# Create a checkpoint
sprite checkpoint create
# List checkpoints
sprite checkpoint list
# Restore from checkpoint
sprite restore <checkpoint-id>

See Checkpoints and Restore for more details.

import { ExecError } from '@fly/sprites';
try {
await sprite.execFile('bash', ['-lc', 'exit 1']);
} catch (error) {
if (error instanceof ExecError) {
console.log('Exit code:', error.exitCode);
console.log('Stdout:', error.stdout);
console.log('Stderr:', error.stderr);
}
}

Always clean up Sprites when you’re done:

Terminal window
sprite destroy my-sprite