Skip to content

Working with Sprites

After you’ve made it through the Quickstart, you’ve got a working Sprite and a sense of how to use it. This page covers what comes next: how Sprites behave over time, how to run persistent processes, how networking works, and how to shape the environment to fit your stack. Use it as a reference as you start building more with Sprites.

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. (SDK config fields are accepted but ignored by the API.)

Set the working directory for command execution:

Terminal window
sprite exec -dir /home/sprite/project npm test
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

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

Add this helper function to your .zshrc or .bashrc to mount your Sprite’s home directory locally:

Terminal window
# Add to ~/.zshrc
sc() {
local sprite_name="${1:-$(sprite use)}"
local mount_point="/tmp/sprite-${sprite_name}"
mkdir -p "$mount_point"
sshfs -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3 \
"sprite@${sprite_name}.sprites.dev:" "$mount_point"
cd "$mount_point"
}

Then use it with:

Terminal window
sc my-sprite # Mounts and cd's to the sprite's filesystem